@7365admin1/layer-common 4.2.22 → 4.2.24
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 +29 -4
- package/components/RolePermissionFormCreate.vue +2 -44
- package/components/RolePermissionFormPreviewUpdate.vue +2 -42
- package/components/RolePermissionMain.vue +0 -6
- package/composables/useLocalAuth.ts +34 -16
- package/package.json +1 -1
- package/plugins/secure-member.client.ts +30 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,30 @@
|
|
|
1
1
|
# @iservice365/layer-common
|
|
2
2
|
|
|
3
|
+
## 4.2.24
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- ce5231a: Stop the app root waiting on two API round trips before it can paint, and start the third one alongside them.
|
|
8
|
+
|
|
9
|
+
`secure-member.client.ts` awaited the member lookup and then, serially, the role document inside `router.beforeEach`, so nothing painted on any route -- not even the neutral "signing you in" hold -- until both had come back. The app root renders no permission-gated surface, so it paid for a gate it does not have. On the root only (`to.name === "index"` and no `memberOnly`) the resolve is now started rather than awaited; every other route, and a root that does carry `memberOnly`, awaits exactly as before, and a route reached while the resolve is still in flight awaits that same promise.
|
|
10
|
+
|
|
11
|
+
`useLocalAuth.getCurrentUser` was the third round trip and it started last, because page setup only runs after the guard returns. The guard now primes it once per page load in parallel with the member lookup, and `getCurrentUser` collapses concurrent callers onto one request so the page asking again costs nothing. `authenticate()` goes through the same request instead of its own `useLazyAsyncData` copy; with no `user` cookie it takes the redirect-to-index branch directly rather than after a request that could only fail.
|
|
12
|
+
|
|
13
|
+
## 4.2.23
|
|
14
|
+
|
|
15
|
+
### Patch Changes
|
|
16
|
+
|
|
17
|
+
- 8290f3c: Remove the web/mobile split from the role permission dialogs
|
|
18
|
+
|
|
19
|
+
A role is one permission list. If a granted module also exists in a mobile app,
|
|
20
|
+
the grant applies there. The dialogs no longer draw a "Web and Mobile" / "Web
|
|
21
|
+
only" legend, no longer suffix module labels with "(Web Only)", no longer take a
|
|
22
|
+
`webOnlyResources` prop, and no longer write a `platform` onto new roles.
|
|
23
|
+
|
|
24
|
+
None of this was ever a gate: `webOnlyResources` was a hardcoded per-app array
|
|
25
|
+
that only chose a chip colour and a label suffix, and the role document's
|
|
26
|
+
`platform` field is read by nothing. Existing role documents are untouched.
|
|
27
|
+
|
|
3
28
|
## 4.2.22
|
|
4
29
|
|
|
5
30
|
### Patch Changes
|
|
@@ -740,11 +765,11 @@
|
|
|
740
765
|
`utils/console-tier.ts` + `composables/useConsoleTier.ts` mirror the server's
|
|
741
766
|
own rule from two endpoints the console already calls, unprojected:
|
|
742
767
|
|
|
743
|
-
|
|
744
|
-
|
|
768
|
+
GET /api/members/user/:user/app/admin the Seven365 staff membership
|
|
769
|
+
GET /api/roles/id/:role that membership's role document
|
|
745
770
|
|
|
746
|
-
|
|
747
|
-
|
|
771
|
+
owner = member.type === "admin" && role.type === "admin" && role.default === true
|
|
772
|
+
staff = member.type === "admin" && role.type === "admin"
|
|
748
773
|
|
|
749
774
|
`role.default` is the marker because it is the only property of a platform
|
|
750
775
|
staff role no API caller can set - `role.controller.ts` validates create and
|
|
@@ -36,19 +36,6 @@
|
|
|
36
36
|
</v-row>
|
|
37
37
|
</v-col>
|
|
38
38
|
|
|
39
|
-
<v-col cols="12" class="mt-3">
|
|
40
|
-
<div class="role-create__legend">
|
|
41
|
-
<span class="d-flex align-center ga-2">
|
|
42
|
-
<v-icon class="role-create__dot--both" size="14">mdi-circle</v-icon>
|
|
43
|
-
Web and Mobile
|
|
44
|
-
</span>
|
|
45
|
-
<span class="d-flex align-center ga-2">
|
|
46
|
-
<v-icon class="role-create__dot--web" size="14">mdi-circle</v-icon>
|
|
47
|
-
Web only
|
|
48
|
-
</span>
|
|
49
|
-
</div>
|
|
50
|
-
</v-col>
|
|
51
|
-
|
|
52
39
|
<v-col cols="12" class="mt-2">
|
|
53
40
|
<AppButton
|
|
54
41
|
variant="ghost"
|
|
@@ -73,7 +60,7 @@
|
|
|
73
60
|
<StatusChip
|
|
74
61
|
class="mr-3"
|
|
75
62
|
:dot="false"
|
|
76
|
-
|
|
63
|
+
tone="info"
|
|
77
64
|
:label="String(selectedActionCount(String(resourceKey)))"
|
|
78
65
|
/>
|
|
79
66
|
</template>
|
|
@@ -181,10 +168,6 @@ const props = defineProps({
|
|
|
181
168
|
type: Boolean,
|
|
182
169
|
default: true,
|
|
183
170
|
},
|
|
184
|
-
webOnlyResources: {
|
|
185
|
-
type: Array as PropType<string[]>,
|
|
186
|
-
default: () => [],
|
|
187
|
-
},
|
|
188
171
|
cancelText: {
|
|
189
172
|
type: String,
|
|
190
173
|
default: "Cancel",
|
|
@@ -213,12 +196,7 @@ const resourceLabels: Record<string, string> = {
|
|
|
213
196
|
};
|
|
214
197
|
|
|
215
198
|
function formatResourceLabel(key: string): string {
|
|
216
|
-
|
|
217
|
-
return props.webOnlyResources.includes(key) ? `${label} (Web Only)` : label;
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
function isWebOnly(resource: string) {
|
|
221
|
-
return props.webOnlyResources.includes(resource);
|
|
199
|
+
return resourceLabels[key] ?? key.replace(/-/g, " ");
|
|
222
200
|
}
|
|
223
201
|
|
|
224
202
|
function isCategoryEnabled(resource: string) {
|
|
@@ -313,7 +291,6 @@ async function submit() {
|
|
|
313
291
|
type: props.type,
|
|
314
292
|
org: props.org,
|
|
315
293
|
site: props.siteId,
|
|
316
|
-
platform: "website",
|
|
317
294
|
});
|
|
318
295
|
emit("success");
|
|
319
296
|
} catch (error: any) {
|
|
@@ -381,25 +358,6 @@ const isAllSelected = computed(() => {
|
|
|
381
358
|
max-height: calc(100vh - 160px);
|
|
382
359
|
}
|
|
383
360
|
|
|
384
|
-
.role-create__legend {
|
|
385
|
-
display: flex;
|
|
386
|
-
align-items: center;
|
|
387
|
-
gap: 16px;
|
|
388
|
-
font-size: var(--fs-breadcrumb);
|
|
389
|
-
color: var(--text2);
|
|
390
|
-
}
|
|
391
|
-
|
|
392
|
-
/* Were `amber-darken-2` / `blue-darken-2` - fixed Vuetify hues that do not
|
|
393
|
-
follow the theme, and the same two the count chip used. Design tones now,
|
|
394
|
-
and the dot and the chip read the same `isWebOnly`, so they cannot drift. */
|
|
395
|
-
.role-create__dot--both {
|
|
396
|
-
color: var(--warn);
|
|
397
|
-
}
|
|
398
|
-
|
|
399
|
-
.role-create__dot--web {
|
|
400
|
-
color: var(--info);
|
|
401
|
-
}
|
|
402
|
-
|
|
403
361
|
/* Was a `variant="outlined"` v-card inside the card - a card on a card. It is
|
|
404
362
|
the list frame, so it takes the design's border and radius and no second
|
|
405
363
|
surface. */
|
|
@@ -7,16 +7,6 @@
|
|
|
7
7
|
<v-form v-model="validForm" :disabled="disable">
|
|
8
8
|
<v-row no-gutters>
|
|
9
9
|
<v-col cols="12" class="mt-4">
|
|
10
|
-
<div class="role-perm__legend">
|
|
11
|
-
<span class="d-flex align-center ga-2">
|
|
12
|
-
<v-icon class="role-perm__dot--both" size="14">mdi-circle</v-icon>
|
|
13
|
-
Web and Mobile
|
|
14
|
-
</span>
|
|
15
|
-
<span class="d-flex align-center ga-2">
|
|
16
|
-
<v-icon class="role-perm__dot--web" size="14">mdi-circle</v-icon>
|
|
17
|
-
Web only
|
|
18
|
-
</span>
|
|
19
|
-
</div>
|
|
20
10
|
<AppButton
|
|
21
11
|
v-if="edit"
|
|
22
12
|
variant="ghost"
|
|
@@ -36,7 +26,7 @@
|
|
|
36
26
|
<StatusChip
|
|
37
27
|
class="mr-3"
|
|
38
28
|
:dot="false"
|
|
39
|
-
|
|
29
|
+
tone="info"
|
|
40
30
|
:label="String(selectedActionCount(String(resourceKey)))"
|
|
41
31
|
/>
|
|
42
32
|
</template>
|
|
@@ -157,10 +147,6 @@ const props = defineProps({
|
|
|
157
147
|
type: Object,
|
|
158
148
|
default: () => ({}),
|
|
159
149
|
},
|
|
160
|
-
webOnlyResources: {
|
|
161
|
-
type: Array as PropType<string[]>,
|
|
162
|
-
default: () => [],
|
|
163
|
-
},
|
|
164
150
|
// "Update role". This dialog had no permission prop at all, so it showed Edit
|
|
165
151
|
// to everyone -- including on the seeded platform-owner role -- and the
|
|
166
152
|
// `canUpdateRole` the apps have been passing to `RolePermissionMain` in good
|
|
@@ -182,12 +168,7 @@ const resourceLabels: Record<string, string> = {
|
|
|
182
168
|
};
|
|
183
169
|
|
|
184
170
|
function formatResourceLabel(key: string) {
|
|
185
|
-
|
|
186
|
-
return props.webOnlyResources.includes(key) ? `${label} (Web Only)` : label;
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
function isWebOnly(resource: string) {
|
|
190
|
-
return props.webOnlyResources.includes(resource);
|
|
171
|
+
return resourceLabels[key] ?? key.replace(/-/g, " ");
|
|
191
172
|
}
|
|
192
173
|
|
|
193
174
|
/**
|
|
@@ -340,27 +321,6 @@ async function submit() {
|
|
|
340
321
|
max-height: calc(100vh - 160px);
|
|
341
322
|
}
|
|
342
323
|
|
|
343
|
-
.role-perm__legend {
|
|
344
|
-
display: flex;
|
|
345
|
-
align-items: center;
|
|
346
|
-
gap: 16px;
|
|
347
|
-
margin-bottom: 12px;
|
|
348
|
-
font-size: var(--fs-breadcrumb);
|
|
349
|
-
color: var(--text2);
|
|
350
|
-
}
|
|
351
|
-
|
|
352
|
-
/* The two legend dots carried `amber-darken-2` and `blue-darken-2` - fixed
|
|
353
|
-
Vuetify hues that do not follow the theme, and the same two hues the count
|
|
354
|
-
chip beside each row used. Both are the design's tones now, and the chip and
|
|
355
|
-
the dot stay in step because they read the same `isWebOnly`. */
|
|
356
|
-
.role-perm__dot--both {
|
|
357
|
-
color: var(--warn);
|
|
358
|
-
}
|
|
359
|
-
|
|
360
|
-
.role-perm__dot--web {
|
|
361
|
-
color: var(--info);
|
|
362
|
-
}
|
|
363
|
-
|
|
364
324
|
/* Was a `variant="outlined"` v-card, i.e. a card inside a card. It is the list
|
|
365
325
|
frame, so it takes the design's card border and radius without laying a
|
|
366
326
|
second surface over the first. */
|
|
@@ -100,7 +100,6 @@
|
|
|
100
100
|
:org="props.orgId"
|
|
101
101
|
:site-id="props.siteId"
|
|
102
102
|
:site-state="siteFieldShown"
|
|
103
|
-
:web-only-resources="props.webOnlyResources"
|
|
104
103
|
@success="success()"
|
|
105
104
|
:type="props.type"
|
|
106
105
|
@success:create-more="getRoles()"
|
|
@@ -118,7 +117,6 @@
|
|
|
118
117
|
:name="name"
|
|
119
118
|
:id="roleId"
|
|
120
119
|
:can-update-role="props.canUpdateRole"
|
|
121
|
-
:web-only-resources="props.webOnlyResources"
|
|
122
120
|
/>
|
|
123
121
|
</v-dialog>
|
|
124
122
|
|
|
@@ -263,10 +261,6 @@ const props = defineProps({
|
|
|
263
261
|
required: true,
|
|
264
262
|
default: () => ({}),
|
|
265
263
|
},
|
|
266
|
-
webOnlyResources: {
|
|
267
|
-
type: Array as PropType<string[]>,
|
|
268
|
-
default: () => [],
|
|
269
|
-
},
|
|
270
264
|
headers: {
|
|
271
265
|
type: Array as PropType<Array<Record<string, any>>>,
|
|
272
266
|
default: () => [
|
|
@@ -1,25 +1,36 @@
|
|
|
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
|
+
|
|
1
8
|
export default function useLocalAuth() {
|
|
2
9
|
const { cookieConfig } = useRuntimeConfig().public;
|
|
3
10
|
|
|
4
11
|
const currentUser = useState<TUser | null>("currentUser", () => null);
|
|
5
12
|
|
|
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.
|
|
6
19
|
async function authenticate() {
|
|
7
20
|
const user = useCookie("user", cookieConfig).value;
|
|
8
21
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
});
|
|
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
|
+
}
|
|
17
29
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
}
|
|
30
|
+
getCurrentUser().catch(() => {
|
|
31
|
+
currentUser.value = null;
|
|
32
|
+
// Redirect to login page if user authentication fails
|
|
33
|
+
navigateTo({ name: "index" });
|
|
23
34
|
});
|
|
24
35
|
}
|
|
25
36
|
|
|
@@ -63,9 +74,16 @@ export default function useLocalAuth() {
|
|
|
63
74
|
currentUser.value = null;
|
|
64
75
|
return null;
|
|
65
76
|
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
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;
|
|
69
87
|
currentUser.value = _user;
|
|
70
88
|
return _user;
|
|
71
89
|
}
|
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.
|
|
5
|
+
"version": "4.2.24",
|
|
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.",
|
|
@@ -13,6 +13,7 @@ export default defineNuxtPlugin(() => {
|
|
|
13
13
|
const { getByUserType } = useMember();
|
|
14
14
|
const { getRoleById } = useRole();
|
|
15
15
|
const { getById } = useOrg();
|
|
16
|
+
const { getCurrentUser } = useLocalAuth();
|
|
16
17
|
|
|
17
18
|
const { userAppRole, userAppRoleStatus, id, orgNature } = useLocalSetup();
|
|
18
19
|
|
|
@@ -21,6 +22,7 @@ export default defineNuxtPlugin(() => {
|
|
|
21
22
|
let resolvedFor: string | null = null;
|
|
22
23
|
let inFlight: Promise<void> | null = null;
|
|
23
24
|
let hasMemberDocument = false;
|
|
25
|
+
let primedUser = false;
|
|
24
26
|
|
|
25
27
|
// Deliberately never redirects and never throws.
|
|
26
28
|
//
|
|
@@ -68,13 +70,40 @@ export default defineNuxtPlugin(() => {
|
|
|
68
70
|
router.beforeEach(async (to) => {
|
|
69
71
|
const userId = useCookie("user").value ?? "";
|
|
70
72
|
|
|
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
|
+
|
|
71
86
|
// Resolve for EVERY authenticated route, not only `memberOnly` ones. Gates
|
|
72
87
|
// are read on pages that carry no such flag -- the staff console cannot
|
|
73
88
|
// carry it at all, it has no organisation in the route -- and until this
|
|
74
89
|
// ran there the role stayed null for the life of the page: gates that
|
|
75
90
|
// default open granted everything, gates that fail closed denied everything.
|
|
76
91
|
// Awaited, so no gate is ever evaluated against an unresolved role.
|
|
77
|
-
|
|
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
|
+
}
|
|
78
107
|
|
|
79
108
|
const isMember = to.meta?.memberOnly;
|
|
80
109
|
|