@7365admin1/layer-common 4.186.0 → 4.187.0

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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,23 @@
1
1
  # @iservice365/layer-common
2
2
 
3
+ ## 4.187.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 2d5d671: Managing agents: the owner role reads with the view-only monitoring rights (Daily Occurrence Book, patrol logs, attendance, checklists) and MA staff roles may be given them, even when the owner's permissions were chosen before these existed.
8
+
9
+ ### Patch Changes
10
+
11
+ - 3dd8a7e: Notification bell and toast: site access request notifications open the organisation Sites page on Requests to approve / Our requests.
12
+
13
+ ## 4.186.1
14
+
15
+ ### Patch Changes
16
+
17
+ - c86da17: MA role editor keeps offering the view rights for provider modules the MA monitors (Daily Occurrence Book, patrol logs, attendance, checklists) even when its module list predates them.
18
+ - d5f68bd: Add Vehicle: the QR sticker picker searches all of the site's blank stickers as you type (e.g. TLR120 or 120), not only the first 50.
19
+ - 7d504ea: Vehicle QR: sticker pick lists show only the sticker number (TLR002 / No. 2); the long code is hidden in the vehicle list (copy button kept).
20
+
3
21
  ## 4.186.0
4
22
 
5
23
  ### Minor Changes
@@ -4054,11 +4072,11 @@ Monthly report: a month that had patrols opens the list of that month's patrol r
4054
4072
  `utils/console-tier.ts` + `composables/useConsoleTier.ts` mirror the server's
4055
4073
  own rule from two endpoints the console already calls, unprojected:
4056
4074
 
4057
- GET /api/members/user/:user/app/admin the Seven365 staff membership
4058
- GET /api/roles/id/:role that membership's role document
4075
+ GET /api/members/user/:user/app/admin the Seven365 staff membership
4076
+ GET /api/roles/id/:role that membership's role document
4059
4077
 
4060
- owner = member.type === "admin" && role.type === "admin" && role.default === true
4061
- staff = member.type === "admin" && role.type === "admin"
4078
+ owner = member.type === "admin" && role.type === "admin" && role.default === true
4079
+ staff = member.type === "admin" && role.type === "admin"
4062
4080
 
4063
4081
  `role.default` is the marker because it is the only property of a platform
4064
4082
  staff role no API caller can set - `role.controller.ts` validates create and
@@ -225,6 +225,7 @@ import {
225
225
  effectiveModules,
226
226
  ownerGrant,
227
227
  siteModulesForOrg,
228
+ withMaMonitorModules,
228
229
  } from "../utils/org-modules";
229
230
  import { withoutDeniedResources } from "../utils/module-routes";
230
231
 
@@ -420,10 +421,13 @@ const offeredPermissions = computed(() =>
420
421
  withoutDeniedResources(catalogueForOwnerGrant(
421
422
  catalogueForOrg(
422
423
  props.permissions ?? {},
423
- effectiveModules(
424
- (orgForModules.value as any)?.modules,
425
- // Only the site's OWN organisation is narrowed by it (owner Q1).
426
- siteModulesForOrg(siteForModules.value as any, props.orgId)
424
+ withMaMonitorModules(
425
+ effectiveModules(
426
+ (orgForModules.value as any)?.modules,
427
+ // Only the site's OWN organisation is narrowed by it (owner Q1).
428
+ siteModulesForOrg(siteForModules.value as any, props.orgId)
429
+ ),
430
+ props.type
427
431
  )
428
432
  ),
429
433
  ownerGrant(orgForModules.value as any, grantRole.value as any, props.type)
@@ -287,11 +287,15 @@
287
287
  "No sticker" adds the vehicle alone. With several plates the
288
288
  sticker goes on the first plate, as Link QR sticker does per plate.
289
289
  -->
290
- <div v-if="prop.qrLink && qrPickItems.length > 1" class="w-100 mt-3">
290
+ <div v-if="prop.qrLink && qrPickerOn" class="w-100 mt-3">
291
291
  <InputLabel title="QR sticker" />
292
292
  <v-autocomplete
293
293
  v-model="qrPick"
294
+ v-model:search="qrPickSearch"
294
295
  :items="qrPickItems"
296
+ no-filter
297
+ placeholder="Type a sticker number, e.g. TLR120 or 120"
298
+ @focus="selectQrPickText"
295
299
  density="comfortable"
296
300
  :hint="newPlateNumbers.filter(Boolean).length > 1 ? 'Linked to the first plate number above.' : 'Type a sticker number to find it.'"
297
301
  persistent-hint
@@ -595,16 +599,53 @@ const {
595
599
  */
596
600
  const qrPicks = ref<BlankPick[]>([]);
597
601
  const qrPick = ref("");
598
- const qrPickItems = computed(() => [
599
- ...qrPicks.value.map((p) => ({ title: blankPickLabel(p), value: p.code })),
600
- { title: "No sticker", value: "" },
601
- ]);
602
+ // the picked sticker stays listed while a search shows other numbers
603
+ const qrPicked = ref<BlankPick | null>(null);
604
+ const qrPickSearch = ref("");
605
+ const qrPickItems = computed(() => {
606
+ const list = qrPicked.value && !qrPicks.value.some((p) => p.code === qrPicked.value!.code)
607
+ ? [qrPicked.value, ...qrPicks.value]
608
+ : qrPicks.value;
609
+ return [...list.map((p) => ({ title: blankPickLabel(p), value: p.code })), { title: "No sticker", value: "" }];
610
+ });
611
+ watch(qrPick, (code) => {
612
+ qrPicked.value = [qrPicked.value, ...qrPicks.value].find((p) => p?.code === code) ?? null;
613
+ });
614
+ // shown when the site has any free sticker - a search with no match keeps it open
615
+ const qrPickerOn = ref(false);
616
+ /*
617
+ * Search the site's whole list on the server as the person types (owner
618
+ * 2026-11-17: a site can hold hundreds of blank stickers; the first 50 alone
619
+ * could not find TLR120).
620
+ */
621
+ // only the latest search may fill the list - a slower earlier answer is dropped
622
+ let qrPickAsked = 0;
623
+ async function loadQrPicks(search = "") {
624
+ const asked = ++qrPickAsked;
625
+ const res = await getBlankStickersBySerial(prop.site, { search, limit: 50 });
626
+ if (asked === qrPickAsked) qrPicks.value = res.items;
627
+ return res;
628
+ }
629
+ // clicking the field selects the picked sticker's text, so typing replaces it
630
+ function selectQrPickText(e: FocusEvent) {
631
+ const input = e.target as HTMLInputElement | null;
632
+ if (input?.select) setTimeout(() => input.select(), 0);
633
+ }
634
+ let qrPickTimer: ReturnType<typeof setTimeout> | undefined;
635
+ watch(qrPickSearch, (v) => {
636
+ clearTimeout(qrPickTimer);
637
+ const text = String(v ?? "");
638
+ // picking a line puts its label in the search text - that is not a search
639
+ if (qrPickItems.value.some((i) => i.title === text)) return;
640
+ qrPickTimer = setTimeout(() => loadQrPicks(text).catch(() => {}), 250);
641
+ });
602
642
  onMounted(async () => {
603
643
  if (!prop.qrLink || prop.mode !== "add") return;
604
644
  try {
605
- const res = await getBlankStickersBySerial(prop.site, { limit: 50 });
606
- qrPicks.value = res.items;
645
+ const res = await loadQrPicks();
646
+ qrPickerOn.value = res.items.length > 0;
607
647
  qrPick.value = res.next?.code ?? "";
648
+ qrPicked.value = res.next ?? null;
608
649
  } catch {
609
650
  qrPicks.value = []; // ponytail: no list, no picker - the vehicle still adds
610
651
  }
@@ -615,7 +656,7 @@ async function linkPickedSticker(plates: string[]): Promise<{ text: string; ok:
615
656
  const code = qrPick.value;
616
657
  const plate = plates[0];
617
658
  if (!code || !plate) return { text: "", ok: true };
618
- const label = blankPickLabel(qrPicks.value.find((p) => p.code === code) ?? { token: code, code });
659
+ const label = blankPickLabel(qrPicked.value?.code === code ? qrPicked.value : qrPicks.value.find((p) => p.code === code) ?? { token: code, code });
619
660
  try {
620
661
  const found = await checkExistingPlates({ site: prop.site, plateNumbers: [plate] });
621
662
  const key = (v: unknown) => String(v ?? "").replace(/[^A-Za-z0-9]/g, "").toUpperCase();
@@ -673,7 +673,7 @@ const qrError = ref("");
673
673
  const qrLinkHint = computed(() => (qrCodeToLink.value ? stickerCodeHint(qrCodeToLink.value) : ""));
674
674
  // the combobox keeps a typed-but-not-committed code in its search text
675
675
  const qrSearch = ref("");
676
- // the pick-list's stickers ("TLR002 - ABCD-..."), by sticker number with the next one first
676
+ // the pick-list's stickers ("TLR002" - the long code only for an unnumbered sticker), by sticker number with the next one first
677
677
  const qrPicks = ref<BlankPick[]>([]);
678
678
  const qrCodes = computed(() => qrPicks.value.map(blankPickLabel));
679
679
  const qrSummary = ref<BlankSummary | null>(null);
@@ -1,14 +1,14 @@
1
1
  <template>
2
2
  <span class="d-inline-flex align-center ga-1 text-caption" data-test="vehicle-sticker-code">
3
3
  <span v-if="label" class="text-medium-emphasis">{{ label }}</span>
4
- <code class="vehicle-sticker-code">{{ code }}</code>
4
+ <!-- the long code is hidden (owner 2026-11-17: too long; the sticker number beside it is what people use) - copy still gives it -->
5
5
  <v-btn :icon="copied ? 'mdi-check' : 'mdi-content-copy'" flat size="x-small" density="compact"
6
- aria-label="Copy sticker code" @click.stop="copy" />
6
+ aria-label="Copy sticker code" title="Copy sticker code" @click.stop="copy" />
7
7
  </span>
8
8
  </template>
9
9
 
10
10
  <script setup lang="ts">
11
- // A blank sticker's printed code, with a copy button. Shown only when the server sent it.
11
+ // Copy button for a sticker's long code (the code itself is not shown). Shown only when the server sent it.
12
12
  const props = defineProps<{ code: string; label?: string }>();
13
13
  const copied = ref(false);
14
14
  async function copy() {
@@ -21,7 +21,3 @@ async function copy() {
21
21
  }
22
22
  }
23
23
  </script>
24
-
25
- <style scoped>
26
- .vehicle-sticker-code { font-size: 0.75rem; letter-spacing: 0.02em; }
27
- </style>
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.186.0",
5
+ "version": "4.187.0",
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.",
@@ -1,5 +1,6 @@
1
1
  import { z } from "zod";
2
2
  import { routeDenied } from "../utils/module-routes.ts";
3
+ import { withMaOwnerMonitorViews } from "../utils/org-modules.ts";
3
4
  import useStaffView, { STAFF_VIEW_ROLE, staffViewCovers } from "../composables/useStaffView.ts";
4
5
 
5
6
  const hexSchema = z
@@ -244,7 +245,12 @@ export default defineNuxtPlugin(() => {
244
245
  // The client's module list is asked for this org and site and does not
245
246
  // need the role, so it goes out while the role is being read.
246
247
  startDenied(userId, id.value ?? "", site);
247
- userAppRole.value = member.role ? await bounded(getRoleById(member.role)) : null;
248
+ const role = member.role ? await bounded(getRoleById(member.role)) : null;
249
+ // An MA owner's role also reads with the providers' monitoring views
250
+ // (owner 2026-11-17). Only a role that could be the owner grant needs the org.
251
+ const maybeOwner = role?.default === true && role?.type === "property_management_agency";
252
+ const org = maybeOwner && id.value ? await bounded(getById(id.value)).catch(() => null) : null;
253
+ userAppRole.value = withMaOwnerMonitorViews(role, org) ?? null;
248
254
  } catch (error) {
249
255
  // Anything that is not a 404 is transient. Stay unresolved so the next
250
256
  // navigation tries again rather than denying for the rest of the session.
@@ -107,6 +107,8 @@ export const VENDOR_ORDER_MODULE = "marketplace-vendor-order";
107
107
  */
108
108
  export const SP_INVITATION_SCREEN = "/service-provider-invitation";
109
109
  export const INVITATIONS_ROUTE = "org-organization-client-invitations";
110
+ /** The organisation app's Sites page (its Access requests panel reads ?requests=incoming|outgoing). */
111
+ export const SITES_ROUTE = "org-organization-sites";
110
112
 
111
113
  /**
112
114
  * What a row is about. `params.kind` when the sender set it; for older rows the
@@ -233,6 +235,8 @@ SITE_PAGES.myVisitors = SITE_PAGES.visitors;
233
235
  export const WEB_TARGET_KINDS = [
234
236
  ...Object.keys(SITE_PAGES),
235
237
  "serviceProviderInvite",
238
+ "siteJoinRequest",
239
+ "siteJoinAnswer",
236
240
  VENDOR_ORDER_MODULE,
237
241
  "robot",
238
242
  "client",
@@ -313,6 +317,21 @@ export function notificationTarget(
313
317
  };
314
318
  }
315
319
 
320
+ // A company asked for access to one of our sites (approve it) or we hear the
321
+ // answer to ours (owner 2026-11-17: the click went nowhere). Both live on the
322
+ // organisation app's Sites page, Access requests panel, on the right tab.
323
+ if (kind === "siteJoinRequest" || kind === "siteJoinAnswer") {
324
+ const org = String(item?.params?.org ?? "").trim() || organization;
325
+ if (!org) return null;
326
+ return {
327
+ name: SITES_ROUTE,
328
+ params: { organization: org },
329
+ query: { requests: kind === "siteJoinRequest" ? "incoming" : "outgoing" },
330
+ app: "org",
331
+ path: `/org/${encodeURIComponent(org)}/sites`,
332
+ };
333
+ }
334
+
316
335
  if (!item) return null;
317
336
  const staff = staffTarget(kind, item);
318
337
  if (staff) return staff;
@@ -189,6 +189,33 @@ export function effectiveModules(
189
189
  return allowed.length ? allowed : org;
190
190
  }
191
191
 
192
+ /**
193
+ * Provider modules a managing agent only MONITORS at its sites (owner
194
+ * 2026-11-17). The MA's own module list does not decide them - core's
195
+ * `MA_MONITOR_MODULES` (module-gate.util.ts) holds the same keys - so the MA
196
+ * role editor keeps offering their view rights even when the list predates them.
197
+ */
198
+ export const MA_MONITOR_MODULES: readonly string[] = Object.freeze([
199
+ "daily-occurrence-books",
200
+ "daily-occurrence-entries",
201
+ "virtual-patrol",
202
+ "nfc-patrol",
203
+ "attendance-mgmt",
204
+ "cleaning-schedule-mgmt",
205
+ "landscape-schedule-mgmt",
206
+ "pest-schedule-mgmt",
207
+ "pool-schedule-mgmt",
208
+ "area-mgmt",
209
+ "unit-mgmt",
210
+ "schedule-task-mgmt",
211
+ ]);
212
+
213
+ /** An MA role editor's module list plus the provider modules it monitors; any other type unchanged. `[]` (= everything) stays `[]`. */
214
+ export function withMaMonitorModules(modules: string[], type: unknown): string[] {
215
+ if (type !== "property_management_agency" || !modules.length) return modules;
216
+ return [...new Set([...modules, ...MA_MONITOR_MODULES])];
217
+ }
218
+
192
219
  /**
193
220
  * The site tier, but only for the organisation that OWNS the site.
194
221
  *
@@ -229,6 +256,35 @@ function isKey(value: unknown): value is string {
229
256
  * its own nature holding an enumerated list, and only roles of that nature are
230
257
  * capped. Anything else - every client invited before this - returns `null`.
231
258
  */
259
+ /**
260
+ * The VIEW rights a managing agent's OWNER holds on the providers' records it
261
+ * monitors (owner decision 2026-11-17), even when Super Admin chose the owner's
262
+ * permissions on Invite Client before these existed. Same strings as core
263
+ * `MA_OWNER_MONITOR_VIEWS` and API-core `site-authz.util`. View only.
264
+ */
265
+ export const MA_OWNER_MONITOR_VIEWS: readonly string[] = Object.freeze([
266
+ "daily-occurrence-books:see-all-daily-occurrence",
267
+ "daily-occurrence-books:see-daily-occurrence-details",
268
+ "daily-occurrence-entries:see-daily-occurrence-entries-details",
269
+ "virtual-patrol:see-all-virtual-patrol-logs",
270
+ "attendance-mgmt:see-all-attendance",
271
+ "cleaning-schedule-mgmt:see-all-schedules",
272
+ ]);
273
+
274
+ /**
275
+ * The signed-in person's role as the gates read it: an MA owner grant role
276
+ * (`ownerGrant`) also holds `MA_OWNER_MONITOR_VIEWS`. Any other role is returned
277
+ * unchanged. Read-only - the stored role is never written.
278
+ */
279
+ export function withMaOwnerMonitorViews<R extends { permissions?: unknown }>(
280
+ role: R | null | undefined,
281
+ org: Parameters<typeof ownerGrant>[0],
282
+ ): R | null | undefined {
283
+ const grant = ownerGrant(org, role as any, "property_management_agency");
284
+ if (!grant || !role) return role;
285
+ return { ...role, permissions: [...new Set([...(role.permissions as string[]), ...MA_OWNER_MONITOR_VIEWS])] };
286
+ }
287
+
232
288
  export function ownerGrant(
233
289
  org: { _id?: unknown; nature?: unknown; invitedRole?: unknown } | null | undefined,
234
290
  grantRole: { _id?: unknown; org?: unknown; type?: unknown; default?: unknown; permissions?: unknown } | null | undefined,
@@ -244,7 +300,10 @@ export function ownerGrant(
244
300
  Array.isArray(permissions) &&
245
301
  permissions.length > 0 &&
246
302
  !permissions.includes("*");
247
- return chosen ? (permissions as unknown[]).map(String) : null;
303
+ if (!chosen) return null;
304
+ const list = (permissions as unknown[]).map(String);
305
+ // An MA owner also holds the providers' monitoring views, so its staff may be given them.
306
+ return type === "property_management_agency" ? [...new Set([...list, ...MA_OWNER_MONITOR_VIEWS])] : list;
248
307
  }
249
308
 
250
309
  /**
@@ -166,10 +166,9 @@ export function blankPickSerial(i: Pick<BlankPick, "serialNo" | "serialLabel">):
166
166
  return n ? String(i.serialLabel ?? "").trim() || `No. ${n}` : "";
167
167
  }
168
168
 
169
- /** "TLR002 - ABCD-EFGH-..." - or just the code for a sticker with no number. */
169
+ /** "TLR002" - the long code only for a sticker with no number (owner 2026-11-17: the code is too long to read). */
170
170
  export function blankPickLabel(i: BlankPick): string {
171
- const sn = blankPickSerial(i);
172
- return sn ? `${sn} - ${i.code}` : i.code;
171
+ return blankPickSerial(i) || i.code;
173
172
  }
174
173
 
175
174
  /** Ascending by sticker number; stickers with no number last, in the order they came. */