@7365admin1/layer-common 4.22.0 → 4.22.1-staging.353

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 (46) hide show
  1. package/CHANGELOG.md +4 -4
  2. package/components/AccessCardAddForm.vue +5 -4
  3. package/components/AccessCardAssignToUnitForm.vue +3 -2
  4. package/components/AccessCardPreviewDialog.vue +4 -3
  5. package/components/Dialog/UpdateMoreAction.vue +11 -1
  6. package/components/DocumentForm.vue +407 -112
  7. package/components/DocumentManagement.vue +213 -12
  8. package/components/EntryPass/QrTemplatePreview.vue +21 -25
  9. package/components/EntryPassInformation.vue +119 -24
  10. package/components/Facility/BookingSetup.vue +63 -0
  11. package/components/HidAccessLogDashboard.vue +29 -5
  12. package/components/HidAccessPermissions.vue +424 -0
  13. package/components/HidIntercomManagement.vue +148 -14
  14. package/components/HidProfileQrCode.vue +323 -0
  15. package/components/HidReaderManagement.vue +26 -0
  16. package/components/HidReaderUserRoster.vue +32 -2
  17. package/components/HidUserEnrollment.vue +833 -152
  18. package/components/InvitationClientForm.vue +19 -1
  19. package/components/Robot/Fleet.vue +712 -0
  20. package/components/Robot/Form.vue +256 -0
  21. package/components/Robot/Map3D.vue +1145 -0
  22. package/components/Robot/Plans.vue +63 -0
  23. package/components/Robot/SpotClean.vue +174 -0
  24. package/components/VisitorManagement.vue +267 -5
  25. package/composables/useAccessManagement.ts +5 -0
  26. package/composables/useDocument.ts +7 -0
  27. package/composables/useFacility.ts +11 -0
  28. package/composables/useHidAmico.ts +117 -0
  29. package/composables/useHidNavigation.ts +25 -1
  30. package/composables/usePeople.ts +19 -0
  31. package/composables/useRobots.ts +324 -0
  32. package/composables/useSiteCategory.ts +45 -0
  33. package/composables/useSiteEntryPassSettings.ts +26 -0
  34. package/composables/useWebUsb.ts +14 -11
  35. package/package.json +2 -2
  36. package/pages/[org]/[site]/access-mgmt/administrator/index.vue +1 -1
  37. package/pages/[org]/[site]/access-mgmt/hid-cards/index.vue +1 -1
  38. package/pages/[org]/[site]/access-mgmt/hid-qr-code/index.vue +23 -0
  39. package/pages/[org]/[site]/access-mgmt/hid-readers/index.vue +1 -1
  40. package/types/document.d.ts +14 -0
  41. package/types/facility.d.ts +4 -0
  42. package/types/people.d.ts +28 -1
  43. package/utils/building-map.ts +537 -0
  44. package/utils/hid-permission-assignments.ts +190 -0
  45. package/utils/occupancy-role.ts +109 -0
  46. package/utils/robot-display.ts +212 -0
@@ -28,6 +28,22 @@ export type HidReaderPayload = {
28
28
  lastCallbackType?: string;
29
29
  };
30
30
 
31
+ export type HidProfileQr = {
32
+ readerId: string;
33
+ userId: string;
34
+ memberId: string;
35
+ hidUserId: string;
36
+ registration: string;
37
+ readerName: string;
38
+ portalName: string;
39
+ qrEnabled: boolean;
40
+ issued: boolean;
41
+ qrValue: string;
42
+ issuedAt: string;
43
+ /** null when the permission lookup itself failed, so "unknown" stays distinct from "no". */
44
+ assigned: boolean | null;
45
+ };
46
+
31
47
  type HidIdentityPayload = {
32
48
  site?: string;
33
49
  hidUserId?: string | number;
@@ -139,6 +155,18 @@ export type HidSipAccountData = {
139
155
  provisionedAt: string;
140
156
  };
141
157
 
158
+ /** One row of the site's SIP account list - who owns the extension, never its password. */
159
+ export type HidSipAccountListItem = {
160
+ _id: string;
161
+ userId: string;
162
+ name: string;
163
+ email: string;
164
+ extension: string;
165
+ username: string;
166
+ status: string;
167
+ provisionedAt: string;
168
+ };
169
+
142
170
  /**
143
171
  * True only for the specific validation error an API that predates core #1878
144
172
  * returns when the discover body carries `site`. Deliberately narrow: after
@@ -166,6 +194,36 @@ export default function useHidAmico() {
166
194
  });
167
195
  }
168
196
 
197
+ /**
198
+ * The signed-in member's own QR code on one reader.
199
+ *
200
+ * No user id in the path: the server takes the caller from the session, so
201
+ * these cannot be pointed at somebody else. `assigned` in the response says
202
+ * whether the HID permissions screen actually admits this member to the
203
+ * reader - issuing a code does not grant access, and the screen has to be
204
+ * able to say so.
205
+ */
206
+ function getProfileQr(readerId: string) {
207
+ return useNuxtApp().$api<{ data: HidProfileQr }>(
208
+ `${basePath}/readers/${readerId}/profile-qr`,
209
+ { method: "GET" },
210
+ );
211
+ }
212
+
213
+ function issueProfileQr(readerId: string) {
214
+ return useNuxtApp().$api<{ data: HidProfileQr }>(
215
+ `${basePath}/readers/${readerId}/profile-qr`,
216
+ { method: "POST" },
217
+ );
218
+ }
219
+
220
+ function deleteProfileQr(readerId: string) {
221
+ return useNuxtApp().$api<{ data: HidProfileQr }>(
222
+ `${basePath}/readers/${readerId}/profile-qr`,
223
+ { method: "DELETE" },
224
+ );
225
+ }
226
+
169
227
  function createReader(payload: HidReaderPayload) {
170
228
  return useNuxtApp().$api<HidApiRecord>(`${basePath}/readers`, {
171
229
  method: "POST",
@@ -414,6 +472,27 @@ export default function useHidAmico() {
414
472
  );
415
473
  }
416
474
 
475
+ function getUserPasswordStatus(readerId: string, hidUserId: string | number) {
476
+ return useNuxtApp().$api<HidApiRecord>(
477
+ `${basePath}/readers/${readerId}/users/${hidUserId}/password`,
478
+ { method: "GET" },
479
+ );
480
+ }
481
+
482
+ function setUserPassword(readerId: string, hidUserId: string | number, password: string) {
483
+ return useNuxtApp().$api<HidApiRecord>(
484
+ `${basePath}/readers/${readerId}/users/${hidUserId}/password`,
485
+ { method: "PUT", body: { password } },
486
+ );
487
+ }
488
+
489
+ function deleteUserPassword(readerId: string, hidUserId: string | number) {
490
+ return useNuxtApp().$api<HidApiRecord>(
491
+ `${basePath}/readers/${readerId}/users/${hidUserId}/password`,
492
+ { method: "DELETE" },
493
+ );
494
+ }
495
+
417
496
  function deleteUserPin(readerId: string, hidUserId: string | number) {
418
497
  return useNuxtApp().$api<{ data: { pinEnrolled: boolean } }>(
419
498
  `${basePath}/readers/${readerId}/users/${hidUserId}/pin`,
@@ -474,6 +553,36 @@ export default function useHidAmico() {
474
553
  );
475
554
  }
476
555
 
556
+ function getSipAccounts(siteId: string, orgId: string) {
557
+ return useNuxtApp().$api<{ data: HidSipAccountListItem[] }>(
558
+ `${basePath}/sites/${siteId}/intercom/sip-accounts`,
559
+ { method: "GET", query: { orgId } },
560
+ );
561
+ }
562
+
563
+ /**
564
+ * Wake the resident's phone for a call the web phone has just placed.
565
+ *
566
+ * The SIP INVITE is the call and travels over the WebSocket, not through the
567
+ * API; this only rings the resident's mobile so somebody is there to answer
568
+ * it. It is therefore fired after the INVITE and never awaited in a way that
569
+ * could fail the call — see `startWebCall` in `HidIntercomManagement.vue`.
570
+ *
571
+ * `notified: false` with a reason is a normal response, not an error: staff
572
+ * extensions and external SIP addresses have no resident behind them.
573
+ */
574
+ function notifyIntercomCall(
575
+ siteId: string,
576
+ payload: { orgId: string; destination: string; callId: string; readerId?: string },
577
+ ) {
578
+ return useNuxtApp().$api<{
579
+ data: { notified: boolean; delivered?: number; reason?: string };
580
+ }>(
581
+ `${basePath}/sites/${siteId}/intercom/notify-call`,
582
+ { method: "POST", body: payload },
583
+ );
584
+ }
585
+
477
586
  function getPermissionCandidates(
478
587
  siteId: string,
479
588
  query: {
@@ -505,6 +614,9 @@ export default function useHidAmico() {
505
614
 
506
615
  return {
507
616
  getReaders,
617
+ getProfileQr,
618
+ issueProfileQr,
619
+ deleteProfileQr,
508
620
  discoverReader,
509
621
  createReader,
510
622
  updateReader,
@@ -530,6 +642,9 @@ export default function useHidAmico() {
530
642
  getUserPinStatus,
531
643
  setUserPin,
532
644
  deleteUserPin,
645
+ getUserPasswordStatus,
646
+ setUserPassword,
647
+ deleteUserPassword,
533
648
  getIdentities,
534
649
  getReaderUsers,
535
650
  getReaderAccessLogs,
@@ -540,6 +655,8 @@ export default function useHidAmico() {
540
655
  makeIntercomCall,
541
656
  finalizeIntercomCall,
542
657
  ensureSipAccount,
658
+ getSipAccounts,
659
+ notifyIntercomCall,
543
660
  getSitePermissions,
544
661
  getPermissionCandidates,
545
662
  updateSitePermissions,
@@ -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
  },
@@ -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,
@@ -0,0 +1,324 @@
1
+ /**
2
+ * The cleaning robots at a site.
3
+ *
4
+ * Two halves, matching the API. `/api/robots` manages the RECORD — register a
5
+ * robot, list an estate's robots. `/api/robots/:id/*` manages the ROBOT itself,
6
+ * and every one of those calls reaches the vendor's cloud, so they are slower
7
+ * and they can fail for reasons that have nothing to do with us (the robot is
8
+ * off, the cloud is unreachable, the credentials were rotated). Screens should
9
+ * show what the failure was rather than an empty list.
10
+ *
11
+ * `appSlug` is sent on the reads so the API narrows the result to the robot
12
+ * types this application presents: a cleaning app never sees a security patrol.
13
+ * It is a visibility rule, not a security boundary — the boundary is the session
14
+ * and the permission — but sending it consistently is what keeps the screens
15
+ * honest.
16
+ */
17
+ export default function useRobots() {
18
+ const appSlug = useRuntimeConfig().public?.appSlug as string | undefined;
19
+
20
+ /** The estate's robots. Credentials are never in this response. */
21
+ async function getRobots({
22
+ organization = "",
23
+ site = "",
24
+ search = "",
25
+ page = 1,
26
+ limit = 10,
27
+ type = "",
28
+ } = {}) {
29
+ return useNuxtApp().$api<Record<string, any>>(
30
+ `/api/robots/organization/${organization}/site/${site}`,
31
+ { method: "GET", query: { search, page, limit, type, appSlug } },
32
+ );
33
+ }
34
+
35
+ /**
36
+ * Register a robot.
37
+ *
38
+ * `appKey` and `appToken` are the vendor cloud credentials. They go up once,
39
+ * are never returned by any read, and must never be put into a query string,
40
+ * a log line or a toast.
41
+ */
42
+ function createRobot(payload: {
43
+ name: string;
44
+ appKey: string;
45
+ appToken: string;
46
+ type?: "cleaning" | "security";
47
+ robotSn?: string;
48
+ metadata: { orgId: string; siteId: string; administratorId?: string };
49
+ }) {
50
+ return useNuxtApp().$api<Record<string, any>>("/api/robots", {
51
+ method: "POST",
52
+ body: payload,
53
+ });
54
+ }
55
+
56
+ /**
57
+ * Rename a robot, or set its serial. The brand and the credentials are not
58
+ * editable: a wrong credential is replaced by removing the robot and adding
59
+ * it again, because the old value is never shown.
60
+ */
61
+ function updateRobot(id: string, payload: { name?: string; robotSn?: string }) {
62
+ return useNuxtApp().$api<Record<string, any>>(`/api/robots/${id}`, {
63
+ method: "PATCH",
64
+ query: { appSlug },
65
+ body: payload,
66
+ });
67
+ }
68
+
69
+ /** Remove a robot. It stops listing and answering; the record is kept. */
70
+ function deleteRobot(id: string) {
71
+ return useNuxtApp().$api<Record<string, any>>(`/api/robots/${id}`, {
72
+ method: "DELETE",
73
+ query: { appSlug },
74
+ });
75
+ }
76
+
77
+ /** Live state — mode, online, whether it can take a job right now. */
78
+ function getRobotState(id: string) {
79
+ return useNuxtApp().$api<Record<string, any>>(
80
+ `/api/robots/${id}/state`,
81
+ { method: "GET", query: { appSlug } },
82
+ );
83
+ }
84
+
85
+ /** The robot's floors, their areas and their metre/pixel transform. */
86
+ function getRobotMaps(id: string) {
87
+ return useNuxtApp().$api<Record<string, any>>(
88
+ `/api/robots/${id}/maps`,
89
+ { method: "GET", query: { appSlug } },
90
+ );
91
+ }
92
+
93
+ /**
94
+ * Signed image URLs for a map's layers.
95
+ *
96
+ * Fetched at the moment of display and never stored: the vendor signs them for
97
+ * about an hour, so a URL kept in a record is a URL that stops working. If a
98
+ * floor plan has gone blank, ask for the URLs again rather than caching harder.
99
+ */
100
+ function getRobotMapImages(id: string, fileKeys: string[]) {
101
+ return useNuxtApp().$api<Record<string, any>>(
102
+ `/api/robots/${id}/map-images`,
103
+ { method: "POST", query: { appSlug }, body: { fileKeys } },
104
+ );
105
+ }
106
+
107
+ /**
108
+ * The robot brands this platform can talk to.
109
+ *
110
+ * A robot record has to name its brand and there is no safe default - sending
111
+ * a robot a command in another brand's protocol is the one mistake the
112
+ * adapter layer exists to prevent. Each brand reports its Open-RMF tier, so
113
+ * somebody choosing one can see what that protocol allows before committing.
114
+ */
115
+ function getRobotBrands() {
116
+ return useNuxtApp().$api<Record<string, any>>("/api/robots/brands", {
117
+ method: "GET",
118
+ });
119
+ }
120
+
121
+ /**
122
+ * Watch one robot's position.
123
+ *
124
+ * `fetch` with a stream reader rather than `EventSource`, because EventSource
125
+ * cannot carry the headers `$api` adds - it would be an unauthenticated
126
+ * request that simply 401s.
127
+ *
128
+ * Returns a `stop`. Calling it aborts the request, which closes the upstream
129
+ * connection to the robot cloud - the server holds one for as long as this
130
+ * one is open, so leaving it running is not free.
131
+ */
132
+ function trackRobot(
133
+ id: string,
134
+ onEvent: (event: Record<string, any>) => void,
135
+ ): { stop: () => void } {
136
+ const controller = new AbortController();
137
+ const base = useRuntimeConfig().public?.apiBase ?? "";
138
+ const query = appSlug ? `?appSlug=${encodeURIComponent(appSlug)}` : "";
139
+
140
+ (async () => {
141
+ try {
142
+ const response = await fetch(`${base}/api/robots/${id}/track${query}`, {
143
+ method: "GET",
144
+ headers: { Accept: "text/event-stream" },
145
+ credentials: "include",
146
+ signal: controller.signal,
147
+ });
148
+ if (!response.ok || !response.body) {
149
+ onEvent({ type: "lost", reason: `The robot stream refused (${response.status}).` });
150
+ return;
151
+ }
152
+
153
+ const reader = response.body.getReader();
154
+ const decoder = new TextDecoder();
155
+ let buffer = "";
156
+
157
+ // Events do not respect chunk boundaries: whatever follows the last
158
+ // blank line stays buffered for the next read, or a pose arriving in
159
+ // two pieces is dropped.
160
+ for (;;) {
161
+ const { done, value } = await reader.read();
162
+ if (done) break;
163
+
164
+ buffer += decoder.decode(value, { stream: true });
165
+ buffer = buffer.replace(/\r\n|\r/g, "\n");
166
+
167
+ const frames = buffer.split("\n\n");
168
+ buffer = frames.pop() ?? "";
169
+
170
+ for (const frame of frames) {
171
+ for (const line of frame.split("\n")) {
172
+ // A line starting ":" is a keep-alive comment, not an event.
173
+ if (!line.startsWith("data:")) continue;
174
+ try {
175
+ onEvent(JSON.parse(line.slice(5).trim()));
176
+ } catch {
177
+ // One malformed frame must not tear down a stream that is
178
+ // otherwise delivering good poses.
179
+ }
180
+ }
181
+ }
182
+ }
183
+ onEvent({ type: "lost", reason: "The robot stream ended." });
184
+ } catch (error: any) {
185
+ if (error?.name === "AbortError") return;
186
+ onEvent({ type: "lost", reason: error?.message ?? "The robot stream failed." });
187
+ }
188
+ })();
189
+
190
+ return { stop: () => controller.abort() };
191
+ }
192
+
193
+ /** The cleaning schedule the vendor cloud holds for this robot. */
194
+ function getRobotPlans(id: string) {
195
+ return useNuxtApp().$api<Record<string, any>>(
196
+ `/api/robots/${id}/plans`,
197
+ { method: "GET", query: { appSlug } },
198
+ );
199
+ }
200
+
201
+ /**
202
+ * Send the robot to work, or bring it home.
203
+ *
204
+ * The API accepts exactly one outstanding job per robot and returns no job id,
205
+ * so a screen cannot track a command after sending it — it re-reads the state.
206
+ * A robot that is not idle is refused by the server with a readable reason;
207
+ * show that reason rather than a generic failure.
208
+ */
209
+ function sendRobotCommand(
210
+ id: string,
211
+ command:
212
+ | { kind: "return" }
213
+ | { kind: "full"; cleanTimes?: number; modeFlag?: number; subModeFlag?: number; levelFlag?: number }
214
+ | { kind: "area"; areas: string[]; cleanTimes?: number; modeFlag?: number; subModeFlag?: number; levelFlag?: number }
215
+ | { kind: "spot"; points: Array<{ x: number; y: number }>; cleanTimes?: number; modeFlag?: number; subModeFlag?: number; levelFlag?: number },
216
+ ) {
217
+ return useNuxtApp().$api<Record<string, any>>(
218
+ `/api/robots/${id}/command`,
219
+ { method: "POST", query: { appSlug }, body: command },
220
+ );
221
+ }
222
+
223
+ /* ---------------------------------------- building maps and lifts */
224
+
225
+ /**
226
+ * A robot's saved building maps, newest first (a summary; `getBuildingMap`
227
+ * has the full layout). No saved map is normal - the 3D view then shows the
228
+ * robot's own floor plans exactly as before.
229
+ */
230
+ function listBuildingMaps(robotId: string, { page = 1, limit = 10 } = {}) {
231
+ return useNuxtApp().$api<Record<string, any>>("/api/robots/building-maps", {
232
+ method: "GET",
233
+ query: { robot: robotId, page, limit, appSlug },
234
+ });
235
+ }
236
+
237
+ function getBuildingMap(mapId: string) {
238
+ return useNuxtApp().$api<Record<string, any>>(`/api/robots/building-maps/${mapId}`, {
239
+ method: "GET",
240
+ });
241
+ }
242
+
243
+ /** Save a first map for a robot's building. The estate comes from the robot. */
244
+ function createBuildingMap(payload: Record<string, any> & { robotId: string }) {
245
+ return useNuxtApp().$api<Record<string, any>>("/api/robots/building-maps", {
246
+ method: "POST",
247
+ query: { appSlug },
248
+ body: payload,
249
+ });
250
+ }
251
+
252
+ /**
253
+ * Save an edited map. `version` is the one the editor loaded; if somebody
254
+ * else saved since, the server refuses (409) rather than overwrite them.
255
+ */
256
+ function updateBuildingMap(mapId: string, payload: Record<string, any> & { version: number }) {
257
+ return useNuxtApp().$api<Record<string, any>>(`/api/robots/building-maps/${mapId}`, {
258
+ method: "PATCH",
259
+ body: payload,
260
+ });
261
+ }
262
+
263
+ function deleteBuildingMap(mapId: string) {
264
+ return useNuxtApp().$api<Record<string, any>>(`/api/robots/building-maps/${mapId}`, {
265
+ method: "DELETE",
266
+ });
267
+ }
268
+
269
+ /** Every lift on the map: the (simulated) car, who holds it, who is waiting. */
270
+ function getLiftQueue(mapId: string) {
271
+ return useNuxtApp().$api<Record<string, any>>(`/api/robots/building-maps/${mapId}/lifts`, {
272
+ method: "GET",
273
+ });
274
+ }
275
+
276
+ function requestLift(
277
+ mapId: string,
278
+ liftName: string,
279
+ payload: { robotId: string; fromFloor: number; toFloor: number },
280
+ ) {
281
+ return useNuxtApp().$api<Record<string, any>>(
282
+ `/api/robots/building-maps/${mapId}/lifts/${encodeURIComponent(liftName)}/sessions`,
283
+ { method: "POST", query: { appSlug }, body: payload },
284
+ );
285
+ }
286
+
287
+ /** Give the lift back, or leave the queue. */
288
+ function releaseLiftSession(sessionId: string) {
289
+ return useNuxtApp().$api<Record<string, any>>(`/api/robots/lift-sessions/${sessionId}/release`, {
290
+ method: "POST",
291
+ });
292
+ }
293
+
294
+ /** This robot's open lift request and its place in the queue, or null. */
295
+ function getRobotLiftSession(robotId: string) {
296
+ return useNuxtApp().$api<Record<string, any>>(`/api/robots/${robotId}/lift-session`, {
297
+ method: "GET",
298
+ query: { appSlug },
299
+ });
300
+ }
301
+
302
+ return {
303
+ listBuildingMaps,
304
+ getBuildingMap,
305
+ createBuildingMap,
306
+ updateBuildingMap,
307
+ deleteBuildingMap,
308
+ getLiftQueue,
309
+ requestLift,
310
+ releaseLiftSession,
311
+ getRobotLiftSession,
312
+ getRobots,
313
+ getRobotBrands,
314
+ trackRobot,
315
+ createRobot,
316
+ updateRobot,
317
+ deleteRobot,
318
+ getRobotState,
319
+ getRobotMaps,
320
+ getRobotMapImages,
321
+ getRobotPlans,
322
+ sendRobotCommand,
323
+ };
324
+ }
@@ -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
+ }
@@ -27,9 +27,35 @@ export default function useSiteEntryPassSettings() {
27
27
  );
28
28
  }
29
29
 
30
+ /**
31
+ * The encrypted ACM URL the access-card screens hand to API-core, which
32
+ * decrypts it and sends the ACM commands to that host.
33
+ *
34
+ * Resolves the site's own "Enter entrypass URL" setting first, the way
35
+ * `VisitorForm` does for contractor passes. The access-card forms used to
36
+ * call `/api/encrypt-acm-url` with no `url`, so every site's door/lift
37
+ * levels and access groups came from the route's hardcoded default host
38
+ * whatever the site had configured. A site with no URL set, or whose
39
+ * settings cannot be read, still gets that default.
40
+ */
41
+ async function getEncryptedAcmUrl(siteId: string): Promise<string> {
42
+ let rawUrl = "";
43
+ try {
44
+ const settings: any = await getBySiteId(siteId);
45
+ rawUrl = String(settings?.data?.settings?.url ?? "").trim();
46
+ } catch {
47
+ // No entry pass settings for this site yet - the default host applies.
48
+ }
49
+ const { encrypted } = await $fetch<{ encrypted: string }>(
50
+ `/api/encrypt-acm-url${rawUrl ? `?url=${encodeURIComponent(rawUrl)}` : ""}`,
51
+ );
52
+ return encrypted;
53
+ }
54
+
30
55
  return {
31
56
  getBySiteId,
32
57
  getById,
33
58
  save,
59
+ getEncryptedAcmUrl,
34
60
  };
35
61
  }
@@ -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,