@autofleet/zehut 1.7.3 → 1.7.4
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/ApiUser.d.ts +3 -1
- package/lib/user/ApiUser.js +5 -1
- package/lib/user/index.js +2 -2
- package/package.json +1 -1
package/lib/user/ApiUser.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
declare type AccountType = 'client' | 'user' | 'service';
|
|
1
2
|
interface EntityPermissions {
|
|
2
3
|
[key: string]: string[];
|
|
3
4
|
}
|
|
@@ -17,7 +18,8 @@ export default class ApiUser {
|
|
|
17
18
|
[key: string]: any;
|
|
18
19
|
};
|
|
19
20
|
emptyUser: boolean;
|
|
20
|
-
|
|
21
|
+
accountType: AccountType | undefined;
|
|
22
|
+
constructor(id?: string, accountType?: AccountType);
|
|
21
23
|
getUserPermissions(): Promise<UserPayload>;
|
|
22
24
|
useCustomPermissionLoader(customPermissionLoader: any): Promise<UserPayload>;
|
|
23
25
|
get businessModels(): string[] | undefined;
|
package/lib/user/ApiUser.js
CHANGED
|
@@ -17,10 +17,13 @@ const node_cache_1 = __importDefault(require("node-cache"));
|
|
|
17
17
|
const services_1 = require("../services");
|
|
18
18
|
const userCache = new node_cache_1.default({ stdTTL: 10 });
|
|
19
19
|
class ApiUser {
|
|
20
|
-
constructor(id) {
|
|
20
|
+
constructor(id, accountType) {
|
|
21
21
|
this.id = id;
|
|
22
22
|
this.emptyUser = !!id;
|
|
23
23
|
this.appPermission = {};
|
|
24
|
+
if (accountType) {
|
|
25
|
+
this.accountType = accountType;
|
|
26
|
+
}
|
|
24
27
|
}
|
|
25
28
|
getUserPermissions() {
|
|
26
29
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -31,6 +34,7 @@ class ApiUser {
|
|
|
31
34
|
return this.privatePermissions;
|
|
32
35
|
}
|
|
33
36
|
const { data } = yield services_1.IdentityNetwork.get(`/api/v1/users/${this.id}/authorization-payload`);
|
|
37
|
+
this.accountType = data.accountType;
|
|
34
38
|
this.privatePermissions = data;
|
|
35
39
|
return this.privatePermissions;
|
|
36
40
|
});
|
package/lib/user/index.js
CHANGED
|
@@ -44,7 +44,7 @@ exports.middleware = (options = {}) => (req, res, next) => __awaiter(void 0, voi
|
|
|
44
44
|
return next();
|
|
45
45
|
});
|
|
46
46
|
exports.middlewareWithDecode = (options = {}) => (req, res, next) => __awaiter(void 0, void 0, void 0, function* () {
|
|
47
|
-
var _a;
|
|
47
|
+
var _a, _b;
|
|
48
48
|
const { eagerLoadUserPermissions, eagerLoadUserPermissionsLegacy, returnErrorIfNoToken, } = options;
|
|
49
49
|
const trace = tracer_1.newTrace('userPayload');
|
|
50
50
|
let decoded;
|
|
@@ -77,7 +77,7 @@ exports.middlewareWithDecode = (options = {}) => (req, res, next) => __awaiter(v
|
|
|
77
77
|
if (userId) {
|
|
78
78
|
req.headers['X-AF-USER-ID'] = userId;
|
|
79
79
|
}
|
|
80
|
-
const userObject = new ApiUser_1.default(userId);
|
|
80
|
+
const userObject = new ApiUser_1.default(userId, (_b = decoded === null || decoded === void 0 ? void 0 : decoded.user) === null || _b === void 0 ? void 0 : _b.accountType);
|
|
81
81
|
if (eagerLoadUserPermissions) {
|
|
82
82
|
yield userObject.getUserPermissions();
|
|
83
83
|
}
|