@autofleet/zehut 1.7.3-beta5 → 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.
@@ -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
- constructor(id?: string);
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;
@@ -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
  });
@@ -96,17 +100,14 @@ class ApiUser {
96
100
  }
97
101
  getUserAppPermissions(appId, clientSecret) {
98
102
  return __awaiter(this, void 0, void 0, function* () {
99
- console.log('getUserAppPermissions1', appId, this.id);
100
103
  if (!this.id || !appId || !clientSecret) {
101
104
  return;
102
105
  }
103
106
  const currentAppPermission = this.appPermission[appId];
104
- console.log('getUserAppPermissions2', currentAppPermission);
105
107
  if (currentAppPermission) {
106
108
  return currentAppPermission;
107
109
  }
108
110
  const cachedResult = userCache.get(`${this.id}:${appId}`);
109
- console.log('getUserAppPermissions3', cachedResult);
110
111
  if (cachedResult) {
111
112
  this.appPermission[appId] = cachedResult;
112
113
  return cachedResult;
@@ -118,7 +119,6 @@ class ApiUser {
118
119
  'x-autofleet-apps-secret': clientSecret,
119
120
  },
120
121
  });
121
- console.log('getUserAppPermissions4', data);
122
122
  userCache.set(this.id, data);
123
123
  this.appPermission[appId] = data;
124
124
  return this.appPermission[appId];
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
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@autofleet/zehut",
3
- "version": "1.7.3-beta5",
3
+ "version": "1.7.4",
4
4
  "description": "manage user's identity",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",