@autofleet/zehut 1.8.2 → 1.8.3
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/lib/user/index.js +30 -22
- package/package.json +1 -1
package/lib/user/index.js
CHANGED
|
@@ -34,32 +34,40 @@ const ApiUser_1 = __importStar(require("./ApiUser"));
|
|
|
34
34
|
const utils_1 = require("../utils");
|
|
35
35
|
const tracer_1 = require("../tracer");
|
|
36
36
|
exports.middleware = (options = {}) => (req, res, next) => __awaiter(void 0, void 0, void 0, function* () {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
const elevatedPermissionsFromHeader = req.headers[ApiUser_1.ELEVATED_PERMISSIONS_HEADER] && req.headers[ApiUser_1.ELEVATED_PERMISSIONS_HEADER].length > 0
|
|
44
|
-
? JSON.parse(req.headers[ApiUser_1.ELEVATED_PERMISSIONS_HEADER])
|
|
45
|
-
: {};
|
|
46
|
-
const userObject = new ApiUser_1.default(userId, 'user', elevatedPermissionsFromHeader);
|
|
47
|
-
if (eagerLoadUserPermissions) {
|
|
48
|
-
if (customPermissionLoader) {
|
|
49
|
-
yield userObject.useCustomPermissionLoader(customPermissionLoader);
|
|
37
|
+
try {
|
|
38
|
+
const { eagerLoadUserPermissions, eagerLoadUserPermissionsLegacy, customPermissionLoader, } = options;
|
|
39
|
+
const userId = req.headers['x-af-user-id'];
|
|
40
|
+
const trace = tracer_1.newTrace('userPayload');
|
|
41
|
+
if (!userId) {
|
|
42
|
+
return next();
|
|
50
43
|
}
|
|
51
|
-
|
|
52
|
-
|
|
44
|
+
const elevatedPermissionsFromHeader = req.headers[ApiUser_1.ELEVATED_PERMISSIONS_HEADER] && req.headers[ApiUser_1.ELEVATED_PERMISSIONS_HEADER].length > 0
|
|
45
|
+
? JSON.parse(req.headers[ApiUser_1.ELEVATED_PERMISSIONS_HEADER])
|
|
46
|
+
: {};
|
|
47
|
+
const userObject = new ApiUser_1.default(userId, 'user', elevatedPermissionsFromHeader);
|
|
48
|
+
if (eagerLoadUserPermissions) {
|
|
49
|
+
if (customPermissionLoader) {
|
|
50
|
+
yield userObject.useCustomPermissionLoader(customPermissionLoader);
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
yield userObject.getUserPermissions();
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
if (eagerLoadUserPermissionsLegacy) {
|
|
57
|
+
yield userObject.getUserPermissionsLegacy();
|
|
53
58
|
}
|
|
59
|
+
req.user = userObject;
|
|
60
|
+
trace.context.set('userObject', userObject);
|
|
61
|
+
// Added in order to support outbreak.
|
|
62
|
+
req.headers['x-af-user-permissions'] = userObject;
|
|
63
|
+
return next();
|
|
54
64
|
}
|
|
55
|
-
|
|
56
|
-
|
|
65
|
+
catch (e) {
|
|
66
|
+
res.status(401);
|
|
67
|
+
return res.json({
|
|
68
|
+
error: 'cannot authenticate user',
|
|
69
|
+
});
|
|
57
70
|
}
|
|
58
|
-
req.user = userObject;
|
|
59
|
-
trace.context.set('userObject', userObject);
|
|
60
|
-
// Added in order to support outbreak.
|
|
61
|
-
req.headers['x-af-user-permissions'] = userObject;
|
|
62
|
-
return next();
|
|
63
71
|
});
|
|
64
72
|
exports.middlewareWithDecode = (options = {}) => (req, res, next) => __awaiter(void 0, void 0, void 0, function* () {
|
|
65
73
|
var _a, _b;
|