@7365admin1/layer-common 4.2.27 → 4.2.29

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,46 @@
1
1
  # @iservice365/layer-common
2
2
 
3
+ ## 4.2.29
4
+
5
+ ### Patch Changes
6
+
7
+ - 5600bf9: ANPR plate toast: restart the 20-second window when a plate is replaced
8
+
9
+ A second plate read arriving before the first toast expired inherited whatever
10
+ was left of the first plate's window, so a read at 19s was visible for about a
11
+ second. Vuetify only restarts a snackbar's countdown when `modelValue` or
12
+ `timeout` actually change value, and re-showing the open toast changed neither.
13
+ The toast now owns its own window and restarts it on every read.
14
+
15
+ ## 4.2.28
16
+
17
+ ### Patch Changes
18
+
19
+ - 182a86e: Make the app root await the role resolve again
20
+
21
+ 4.2.24 carved `to.name === "index"` out of the `await` in the `secure-member`
22
+ route guard: the app root started the member/role lookup and returned without
23
+ it, so the first screen painted with `userAppRole` still null.
24
+
25
+ Every permission gate in this package fails closed on a null role -
26
+ `DashboardMain.vue`'s `canViewWidget` returns `false` the moment `permissions`
27
+ is undefined - so a signed-in user could reach a first paint with no widgets
28
+ and no module navigation. The saving was two round trips on one screen; the
29
+ cost was a gate evaluated against an unresolved role.
30
+
31
+ The guard awaits on every route again, root included, exactly as it did in
32
+ 4.2.23. `useLocalAuth` goes back with it: its shared-request and
33
+ fire-and-forget `authenticate()` changes shipped in the same change and are
34
+ only meaningful alongside it.
35
+
36
+ Three tests pin it: the root guard is held open while the lookup is deferred
37
+ and observed not to return; the permissions a gate reads are asserted non-null
38
+ the instant the guard returns; and the shipped source is checked for any
39
+ route-name exception to the await.
40
+
41
+ The ANPR plate toast (4.2.25), the notification-settings channel summary
42
+ (4.2.26) and the Invite Client role picker (4.2.27) are unchanged.
43
+
3
44
  ## 4.2.27
4
45
 
5
46
  ### Patch Changes
@@ -801,11 +842,11 @@
801
842
  `utils/console-tier.ts` + `composables/useConsoleTier.ts` mirror the server's
802
843
  own rule from two endpoints the console already calls, unprojected:
803
844
 
804
- GET /api/members/user/:user/app/admin the Seven365 staff membership
805
- GET /api/roles/id/:role that membership's role document
845
+ GET /api/members/user/:user/app/admin the Seven365 staff membership
846
+ GET /api/roles/id/:role that membership's role document
806
847
 
807
- owner = member.type === "admin" && role.type === "admin" && role.default === true
808
- staff = member.type === "admin" && role.type === "admin"
848
+ owner = member.type === "admin" && role.type === "admin" && role.default === true
849
+ staff = member.type === "admin" && role.type === "admin"
809
850
 
810
851
  `role.default` is the marker because it is the only property of a platform
811
852
  staff role no API caller can set - `role.controller.ts` validates create and
@@ -43,7 +43,7 @@
43
43
  <v-snackbar
44
44
  v-if="!isUnregisteredVisitorRoute && enableUnregisteredSnackbar && canViewVisitor"
45
45
  v-model="snackBarMessage.modal"
46
- :timeout="snackBarMessage.timeout"
46
+ :timeout="-1"
47
47
  location="bottom center"
48
48
  class="app-toast anpr-toast"
49
49
  multi-line
@@ -153,7 +153,6 @@ const visitorList = ref<TVisitorSocketData[]>([]);
153
153
  const lastPlateNumber = ref("");
154
154
 
155
155
  const snackBarMessage = reactive({
156
- timeout: 3000,
157
156
  /** The camera's raw read. `plateToast` decides what is drawn for it. */
158
157
  plateNumber: "",
159
158
  modal: false,
@@ -161,6 +160,10 @@ const snackBarMessage = reactive({
161
160
 
162
161
  const plateCopy = computed(() => plateToast(snackBarMessage.plateNumber));
163
162
 
163
+ const plateToastWindow = createPlateToastWindow(() => {
164
+ snackBarMessage.modal = false;
165
+ });
166
+
164
167
  const permanentMessageDialog = reactive({
165
168
  modal: false,
166
169
  text: "",
@@ -257,7 +260,9 @@ const showPlate = (plateNumber: string) => {
257
260
 
258
261
  snackBarMessage.plateNumber = plateNumber;
259
262
  snackBarMessage.modal = true;
260
- snackBarMessage.timeout = 20000;
263
+ // Restart the 20s window from zero. A replacement plate gets a full window
264
+ // of its own; without this it inherited whatever was left of the one before.
265
+ plateToastWindow.restart();
261
266
  };
262
267
 
263
268
  const connectSocket = () => {
@@ -385,6 +390,10 @@ const onEscape = (event: KeyboardEvent) => {
385
390
  watch(
386
391
  () => snackBarMessage.modal,
387
392
  (open) => {
393
+ // Every route to a closed toast - the close button, Escape, the
394
+ // unregistered tab, the site setting - lands here, so the outstanding
395
+ // window is dropped in one place rather than at each of them.
396
+ if (!open) plateToastWindow.cancel();
388
397
  if (typeof document === "undefined") return;
389
398
  if (open) document.addEventListener("keydown", onEscape);
390
399
  else document.removeEventListener("keydown", onEscape);
@@ -392,6 +401,7 @@ watch(
392
401
  );
393
402
 
394
403
  onUnmounted(() => {
404
+ plateToastWindow.cancel();
395
405
  if (typeof document !== "undefined") {
396
406
  document.removeEventListener("keydown", onEscape);
397
407
  }
@@ -1,36 +1,25 @@
1
- // One in-flight `GET /api/users/id/:id` per page load, shared by every caller.
2
- // These apps are `ssr: false`, so module scope is exactly one browser session.
3
- // The route guard starts this request in parallel with the member lookup and
4
- // the first screen asks for it again on setup; without this that is two
5
- // identical requests instead of one.
6
- let currentUserRequest: Promise<any> | null = null;
7
-
8
1
  export default function useLocalAuth() {
9
2
  const { cookieConfig } = useRuntimeConfig().public;
10
3
 
11
4
  const currentUser = useState<TUser | null>("currentUser", () => null);
12
5
 
13
- // Goes through the same request `getCurrentUser` makes, so it joins the one
14
- // the route guard already started instead of issuing a second.
15
- //
16
- // DELIBERATELY NOT AWAITED INSIDE. 19 pages call this with a top-level
17
- // `await`, and the `useLazyAsyncData` it replaces returned before its request
18
- // did; awaiting the request here would newly suspend every one of them.
19
6
  async function authenticate() {
20
7
  const user = useCookie("user", cookieConfig).value;
21
8
 
22
- // No cookie used to mean a request for `/api/users/id/undefined` that could
23
- // only fail. Same destination, one round trip earlier.
24
- if (!user) {
25
- currentUser.value = null;
26
- navigateTo({ name: "index" });
27
- return;
28
- }
9
+ const { data: getCurrentUserReq, error: getCurrentUserErr } =
10
+ await useLazyAsyncData("getCurrentUser", () =>
11
+ useNuxtApp().$api<TUser>(`/api/users/id/${user}`)
12
+ );
29
13
 
30
- getCurrentUser().catch(() => {
31
- currentUser.value = null;
32
- // Redirect to login page if user authentication fails
33
- navigateTo({ name: "index" });
14
+ watchEffect(() => {
15
+ currentUser.value = (getCurrentUserReq.value as TUser | null) ?? null;
16
+ });
17
+
18
+ watchEffect(() => {
19
+ if (getCurrentUserErr.value) {
20
+ // Redirect to login page if user authentication fails
21
+ navigateTo({ name: "index" });
22
+ }
34
23
  });
35
24
  }
36
25
 
@@ -74,16 +63,9 @@ export default function useLocalAuth() {
74
63
  currentUser.value = null;
75
64
  return null;
76
65
  }
77
- if (!currentUserRequest) {
78
- currentUserRequest = useNuxtApp()
79
- .$api<TUser>(`/api/users/id/${user}`, { method: "GET" })
80
- .finally(() => {
81
- // Cleared on success AND on failure: this collapses callers that
82
- // overlap, it does not cache the answer.
83
- currentUserRequest = null;
84
- });
85
- }
86
- const _user = (await currentUserRequest) as TUser;
66
+ const _user = await useNuxtApp().$api<TUser>(`/api/users/id/${user}`, {
67
+ method: "GET",
68
+ });
87
69
  currentUser.value = _user;
88
70
  return _user;
89
71
  }
@@ -0,0 +1,56 @@
1
+ /**
2
+ * The 20-second window a plate toast stays up for.
3
+ *
4
+ * Vuetify does NOT restart a snackbar's countdown when an already-open
5
+ * snackbar is re-shown with the same timeout. `VSnackbar` starts its timer
6
+ * from two watchers only -
7
+ *
8
+ * watch(isActive, startTimeout)
9
+ * watch(() => props.timeout, startTimeout)
10
+ *
11
+ * - and a Vue watcher does not fire when the value it watches is assigned the
12
+ * value it already holds. Re-showing the toast with `modal = true` and
13
+ * `timeout = 20000` while both were already `true` and `20000` therefore left
14
+ * the FIRST plate's timer running: a replacement read arriving at 19s
15
+ * inherited the 1s that was left of the plate before it, and was gone before
16
+ * the guard could read it.
17
+ *
18
+ * So the window is owned here instead of by Vuetify. The snackbar runs with
19
+ * `timeout: -1` (Vuetify's "never close on your own") and every plate clears
20
+ * the outstanding timer and starts a fresh one. This is the same shape the
21
+ * React Native app already uses (`visitor-socket-monitor.tsx`), which is why
22
+ * the defect never appeared there.
23
+ */
24
+ export const PLATE_TOAST_MS = 20000;
25
+
26
+ export type TPlateToastWindow = {
27
+ /** Start the window, or restart it from zero if one is already running. */
28
+ restart: () => void;
29
+ /** Drop the outstanding window - the toast was closed by something else. */
30
+ cancel: () => void;
31
+ };
32
+
33
+ export const createPlateToastWindow = (
34
+ close: () => void,
35
+ ms: number = PLATE_TOAST_MS,
36
+ ): TPlateToastWindow => {
37
+ let handle: ReturnType<typeof setTimeout> | null = null;
38
+
39
+ const cancel = () => {
40
+ if (handle !== null) {
41
+ clearTimeout(handle);
42
+ handle = null;
43
+ }
44
+ };
45
+
46
+ return {
47
+ restart: () => {
48
+ cancel();
49
+ handle = setTimeout(() => {
50
+ handle = null;
51
+ close();
52
+ }, ms);
53
+ },
54
+ cancel,
55
+ };
56
+ };
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.2.27",
5
+ "version": "4.2.29",
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.",
@@ -36,7 +36,7 @@
36
36
  "build": "nuxt build .playground",
37
37
  "generate": "nuxt generate .playground",
38
38
  "preview": "nuxt preview .playground",
39
- "test": "esbuild composables/useVisitorSocket.ts --format=esm --outfile=test/.build/useVisitorSocket.mjs --log-level=error && node --experimental-strip-types --test \"test/*.test.mjs\" && yarn test:units",
39
+ "test": "esbuild composables/useVisitorSocket.ts --format=esm --outfile=test/.build/useVisitorSocket.mjs --log-level=error && esbuild composables/usePlateToastWindow.ts --format=esm --outfile=test/.build/usePlateToastWindow.mjs --log-level=error && node --experimental-strip-types --test \"test/*.test.mjs\" && yarn test:units",
40
40
  "test:units": "node --experimental-strip-types --test \"utils/*.test.ts\"",
41
41
  "release": "yarn run build && changeset publish"
42
42
  },
@@ -13,7 +13,6 @@ export default defineNuxtPlugin(() => {
13
13
  const { getByUserType } = useMember();
14
14
  const { getRoleById } = useRole();
15
15
  const { getById } = useOrg();
16
- const { getCurrentUser } = useLocalAuth();
17
16
 
18
17
  const { userAppRole, userAppRoleStatus, id, orgNature } = useLocalSetup();
19
18
 
@@ -22,7 +21,6 @@ export default defineNuxtPlugin(() => {
22
21
  let resolvedFor: string | null = null;
23
22
  let inFlight: Promise<void> | null = null;
24
23
  let hasMemberDocument = false;
25
- let primedUser = false;
26
24
 
27
25
  // Deliberately never redirects and never throws.
28
26
  //
@@ -70,40 +68,13 @@ export default defineNuxtPlugin(() => {
70
68
  router.beforeEach(async (to) => {
71
69
  const userId = useCookie("user").value ?? "";
72
70
 
73
- // The signed-in user's own record is a THIRD round trip and almost every
74
- // first screen wants it, but page setup only runs once the guard below has
75
- // returned -- so it used to start after both lookups had finished. Started
76
- // here it runs alongside them. `getCurrentUser` collapses concurrent
77
- // callers onto one request, so the page asking for it again costs nothing.
78
- if (userId && !primedUser) {
79
- primedUser = true;
80
- void getCurrentUser().catch(() => {
81
- // A failed prime is not this guard's business: every caller that needs
82
- // the user asks again and handles its own failure.
83
- });
84
- }
85
-
86
71
  // Resolve for EVERY authenticated route, not only `memberOnly` ones. Gates
87
72
  // are read on pages that carry no such flag -- the staff console cannot
88
73
  // carry it at all, it has no organisation in the route -- and until this
89
74
  // ran there the role stayed null for the life of the page: gates that
90
75
  // default open granted everything, gates that fail closed denied everything.
91
76
  // Awaited, so no gate is ever evaluated against an unresolved role.
92
- //
93
- // The ONE exception is the app root. It renders no permission-gated
94
- // surface -- it reads the signed-in email, and leaves -- so waiting two
95
- // serial round trips there delays the first paint of every app by the
96
- // length of both and buys nothing. Started, not awaited. Every other
97
- // route, root-or-not, still awaits, and a route reached while this is
98
- // still in flight awaits THIS promise: `resolveAppRole` returns the
99
- // in-flight one rather than starting a second.
100
- if (userId) {
101
- if (to.name === "index" && !to.meta?.memberOnly) {
102
- void resolveAppRole(userId);
103
- } else {
104
- await resolveAppRole(userId);
105
- }
106
- }
77
+ if (userId) await resolveAppRole(userId);
107
78
 
108
79
  const isMember = to.meta?.memberOnly;
109
80