@7365admin1/layer-common 4.97.1-staging.648 → 4.97.1-staging.649
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.
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { EntryPassNotSetUpError } from "../utils/entrypass-failure";
|
|
2
|
+
|
|
1
3
|
export default function useSiteEntryPassSettings() {
|
|
2
4
|
function getBySiteId(siteId: string) {
|
|
3
5
|
return useNuxtApp().$api<Record<string, any>>(
|
|
@@ -37,8 +39,14 @@ export default function useSiteEntryPassSettings() {
|
|
|
37
39
|
* levels and access groups came from the route's hardcoded default host
|
|
38
40
|
* whatever the site had configured. A site with no URL set, or whose
|
|
39
41
|
* settings cannot be read, still gets that default.
|
|
42
|
+
*
|
|
43
|
+
* `requireSiteUrl` (Add Access Card, DV-0887): no default. A site with no
|
|
44
|
+
* URL set throws `EntryPassNotSetUpError`, so the screen can say so.
|
|
40
45
|
*/
|
|
41
|
-
async function getEncryptedAcmUrl(
|
|
46
|
+
async function getEncryptedAcmUrl(
|
|
47
|
+
siteId: string,
|
|
48
|
+
options: { requireSiteUrl?: boolean } = {},
|
|
49
|
+
): Promise<string> {
|
|
42
50
|
let rawUrl = "";
|
|
43
51
|
try {
|
|
44
52
|
const settings: any = await getBySiteId(siteId);
|
|
@@ -46,6 +54,7 @@ export default function useSiteEntryPassSettings() {
|
|
|
46
54
|
} catch {
|
|
47
55
|
// No entry pass settings for this site yet - the default host applies.
|
|
48
56
|
}
|
|
57
|
+
if (!rawUrl && options.requireSiteUrl) throw new EntryPassNotSetUpError();
|
|
49
58
|
const { encrypted } = await $fetch<{ encrypted: string }>(
|
|
50
59
|
`/api/encrypt-acm-url${rawUrl ? `?url=${encodeURIComponent(rawUrl)}` : ""}`,
|
|
51
60
|
);
|
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.97.1-staging.
|
|
5
|
+
"version": "4.97.1-staging.649",
|
|
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.",
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What went wrong when an access-card screen asked EntryPass for its lists
|
|
3
|
+
* (door locations, lift access levels, access groups), in words a site admin
|
|
4
|
+
* can act on.
|
|
5
|
+
*
|
|
6
|
+
* API-core answers every EntryPass failure with a 400 whose `message` is the
|
|
7
|
+
* underlying error, e.g. "Request failed with status code 500" when the
|
|
8
|
+
* EntryPass host itself errors. The screens used to replace all of these with
|
|
9
|
+
* one "EntryPass server is unavailable" toast (DV-0887).
|
|
10
|
+
*
|
|
11
|
+
* - not-set-up the site has no EntryPass address saved
|
|
12
|
+
* - no-response the request never got an answer (timeout, refused, offline)
|
|
13
|
+
* - error EntryPass, or the API in front of it, answered with an error
|
|
14
|
+
*/
|
|
15
|
+
export type EntryPassFailureKind = "not-set-up" | "no-response" | "error";
|
|
16
|
+
|
|
17
|
+
export type EntryPassFailure = {
|
|
18
|
+
kind: EntryPassFailureKind;
|
|
19
|
+
title: string;
|
|
20
|
+
body: string;
|
|
21
|
+
/** The server's own message, when there is one. */
|
|
22
|
+
detail: string;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
/** Thrown when a screen requires the site's own EntryPass address and it has none. */
|
|
26
|
+
export class EntryPassNotSetUpError extends Error {
|
|
27
|
+
constructor() {
|
|
28
|
+
super("EntryPass is not set up for this site.");
|
|
29
|
+
this.name = "EntryPassNotSetUpError";
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const NO_RESPONSE =
|
|
34
|
+
/timeout|timed out|ECONNREFUSED|ECONNRESET|ENOTFOUND|EAI_AGAIN|socket hang up|network ?error|fetch failed|failed to fetch/i;
|
|
35
|
+
|
|
36
|
+
/** The server's message for a failed request, or the error's own. */
|
|
37
|
+
export function entryPassErrorMessage(error: unknown): string {
|
|
38
|
+
const e = error as any;
|
|
39
|
+
return String(e?.data?.message ?? e?.message ?? "").trim();
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function listText(lists: string[]): string {
|
|
43
|
+
if (lists.length <= 1) return lists[0] ?? "the lists";
|
|
44
|
+
return `${lists.slice(0, -1).join(", ")} and ${lists[lists.length - 1]}`;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* @param lists the lists that could not be loaded, e.g. ["access groups"]
|
|
49
|
+
*/
|
|
50
|
+
export function describeEntryPassFailure(
|
|
51
|
+
error: unknown,
|
|
52
|
+
lists: string[] = ["door locations", "access groups"],
|
|
53
|
+
): EntryPassFailure {
|
|
54
|
+
const e = error as any;
|
|
55
|
+
|
|
56
|
+
if (e instanceof EntryPassNotSetUpError || e?.name === "EntryPassNotSetUpError") {
|
|
57
|
+
return {
|
|
58
|
+
kind: "not-set-up",
|
|
59
|
+
title: "EntryPass is not set up for this site.",
|
|
60
|
+
body: "Door locations and access groups come from EntryPass, so a physical card can't be added yet. Ask an administrator to set the EntryPass address in Access Management settings.",
|
|
61
|
+
detail: "",
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const detail = entryPassErrorMessage(error);
|
|
66
|
+
const status = e?.statusCode ?? e?.status ?? e?.response?.status;
|
|
67
|
+
// No status and no body: the request itself never got an answer.
|
|
68
|
+
const noAnswer = !status && !e?.data;
|
|
69
|
+
|
|
70
|
+
if (noAnswer || NO_RESPONSE.test(detail)) {
|
|
71
|
+
return {
|
|
72
|
+
kind: "no-response",
|
|
73
|
+
title: "EntryPass did not respond.",
|
|
74
|
+
body: "Door locations and access groups could not be loaded. Try again in a moment. If it keeps happening, contact your administrator.",
|
|
75
|
+
detail,
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
return {
|
|
80
|
+
kind: "error",
|
|
81
|
+
title: `EntryPass could not load the ${listText(lists)}.`,
|
|
82
|
+
body: detail
|
|
83
|
+
? `It answered: "${detail}". Try again, or contact your administrator with this message.`
|
|
84
|
+
: "Try again, or contact your administrator.",
|
|
85
|
+
detail,
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/** One line for a toast: the title, plus the server's message when there is one. */
|
|
90
|
+
export function entryPassFailureToast(failure: EntryPassFailure): string {
|
|
91
|
+
return failure.kind === "error" && failure.detail
|
|
92
|
+
? `${failure.title} It answered: "${failure.detail}".`
|
|
93
|
+
: failure.title;
|
|
94
|
+
}
|