@7365admin1/layer-common 4.11.1-staging.316 → 4.11.1-staging.318
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/composables/useMember.ts
CHANGED
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.11.1-staging.
|
|
5
|
+
"version": "4.11.1-staging.318",
|
|
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.",
|
|
@@ -9,6 +9,26 @@ function statusOf(error: any) {
|
|
|
9
9
|
return error?.statusCode ?? error?.status ?? error?.response?.status;
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
+
/*
|
|
13
|
+
* This guard runs before EVERY navigation and awaits these lookups, so one that
|
|
14
|
+
* never answers held the first page - every app's sign-in card included - blank
|
|
15
|
+
* for ever. Past this bound a lookup counts as a transient failure: the role
|
|
16
|
+
* stays unresolved (exactly as for a 502) and the next navigation retries. Same
|
|
17
|
+
* bound the module deny list already uses (`getDeniedModules`, 5 s).
|
|
18
|
+
*/
|
|
19
|
+
export const LOOKUP_TIMEOUT_MS = 5000;
|
|
20
|
+
|
|
21
|
+
function bounded<T>(request: Promise<T>): Promise<T> {
|
|
22
|
+
let timer: ReturnType<typeof setTimeout> | undefined;
|
|
23
|
+
const timeout = new Promise<never>((_, reject) => {
|
|
24
|
+
timer = setTimeout(
|
|
25
|
+
() => reject(Object.assign(new Error("Lookup timed out."), { statusCode: 408 })),
|
|
26
|
+
LOOKUP_TIMEOUT_MS,
|
|
27
|
+
);
|
|
28
|
+
});
|
|
29
|
+
return Promise.race([request, timeout]).finally(() => clearTimeout(timer));
|
|
30
|
+
}
|
|
31
|
+
|
|
12
32
|
/** A route param that is a real id, or "": a malformed one is never sent. */
|
|
13
33
|
function idParam(value: unknown) {
|
|
14
34
|
return hexSchema.safeParse(value).success ? String(value) : "";
|
|
@@ -59,10 +79,10 @@ export default defineNuxtPlugin(() => {
|
|
|
59
79
|
try {
|
|
60
80
|
// The org query is not sent: the endpoint keys on user + app type only, so
|
|
61
81
|
// the role does not depend on which organisation is in the current route.
|
|
62
|
-
const member = await getByUserType(userId, APP);
|
|
82
|
+
const member = await bounded(getByUserType(userId, APP));
|
|
63
83
|
hasMemberDocument = true;
|
|
64
84
|
id.value = member.org ?? "";
|
|
65
|
-
userAppRole.value = member.role ? await getRoleById(member.role) : null;
|
|
85
|
+
userAppRole.value = member.role ? await bounded(getRoleById(member.role)) : null;
|
|
66
86
|
} catch (error) {
|
|
67
87
|
userAppRole.value = null;
|
|
68
88
|
hasMemberDocument = false;
|
|
@@ -160,7 +180,7 @@ export default defineNuxtPlugin(() => {
|
|
|
160
180
|
}
|
|
161
181
|
|
|
162
182
|
try {
|
|
163
|
-
const orgResult = await getById(org);
|
|
183
|
+
const orgResult = await bounded(getById(org));
|
|
164
184
|
if (orgResult) orgNature.value = orgResult.nature ?? "";
|
|
165
185
|
} catch (error) {
|
|
166
186
|
// Cosmetic only, and it never blocked navigation before either.
|