@remit/backend 2.1.0 → 2.1.1
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/dist/src/handlers/people.js +27 -13
- package/package.json +1 -1
|
@@ -1,17 +1,31 @@
|
|
|
1
|
+
import { PeopleErrorCode } from "@remit/domain-enums";
|
|
1
2
|
import { getPeopleDirectory } from "../service/people-directory.js";
|
|
2
3
|
const CLIENT_IP_HEADER = "x-remit-client-ip";
|
|
3
|
-
const refuse = (statusCode, code, message) => ({ statusCode, body: { code, message } });
|
|
4
4
|
const REFUSALS = {
|
|
5
|
-
|
|
5
|
+
[PeopleErrorCode.SignInDisabled]: [
|
|
6
|
+
403,
|
|
7
|
+
"Sign-in is turned off on this server.",
|
|
8
|
+
],
|
|
9
|
+
[PeopleErrorCode.CallerDisabled]: [403, "Your account is disabled."],
|
|
10
|
+
[PeopleErrorCode.ForeignOrigin]: [
|
|
11
|
+
403,
|
|
12
|
+
"This request came from a page this server does not serve.",
|
|
13
|
+
],
|
|
14
|
+
[PeopleErrorCode.StepUpRequired]: [403, "Confirm your password again."],
|
|
15
|
+
[PeopleErrorCode.WrongPassword]: [403, "That password is not right."],
|
|
16
|
+
[PeopleErrorCode.StepUpLocked]: [
|
|
17
|
+
429,
|
|
18
|
+
"Too many wrong passwords. Try again in 15 minutes.",
|
|
19
|
+
],
|
|
20
|
+
[PeopleErrorCode.CannotDisableSelf]: [
|
|
21
|
+
409,
|
|
22
|
+
"You cannot disable your own account.",
|
|
23
|
+
],
|
|
6
24
|
not_found: [404, "Not found"],
|
|
7
|
-
step_up_required: [403, "Confirm your password again."],
|
|
8
|
-
wrong_password: [403, "That password is not right."],
|
|
9
|
-
step_up_locked: [429, "Too many wrong passwords. Try again in 15 minutes."],
|
|
10
|
-
cannot_disable_self: [409, "You cannot disable your own account."],
|
|
11
25
|
};
|
|
12
|
-
const refusalOf = (
|
|
13
|
-
const [statusCode, message] = REFUSALS[
|
|
14
|
-
return
|
|
26
|
+
const refusalOf = (code) => {
|
|
27
|
+
const [statusCode, message] = REFUSALS[code];
|
|
28
|
+
return { statusCode, body: { code, message } };
|
|
15
29
|
};
|
|
16
30
|
const headerOf = (context, name) => {
|
|
17
31
|
const headers = context.request.headers;
|
|
@@ -39,18 +53,18 @@ const guard = (context, ctx, targetId, unsafe) => {
|
|
|
39
53
|
callerId: ctx.identity.sub,
|
|
40
54
|
clientIp: headerOf(context, CLIENT_IP_HEADER) ?? "unknown",
|
|
41
55
|
};
|
|
42
|
-
const refuseAudited = (outcome, code
|
|
56
|
+
const refuseAudited = (outcome, code) => {
|
|
43
57
|
directory.recordRefusal({ ...request, targetId, outcome });
|
|
44
|
-
return
|
|
58
|
+
return refusalOf(code);
|
|
45
59
|
};
|
|
46
60
|
if (auth.signIn === "Disabled") {
|
|
47
|
-
return refuseAudited("RefusedSignInOff",
|
|
61
|
+
return refuseAudited("RefusedSignInOff", PeopleErrorCode.SignInDisabled);
|
|
48
62
|
}
|
|
49
63
|
const origin = headerOf(context, "origin");
|
|
50
64
|
if (unsafe &&
|
|
51
65
|
origin !== undefined &&
|
|
52
66
|
!ctx.config.corsAllowedOrigins.includes(origin)) {
|
|
53
|
-
return refuseAudited("RefusedForeignOrigin",
|
|
67
|
+
return refuseAudited("RefusedForeignOrigin", PeopleErrorCode.ForeignOrigin);
|
|
54
68
|
}
|
|
55
69
|
return request;
|
|
56
70
|
};
|