@autofleet/zehut 1.7.0-beta1 → 1.7.0-beta3

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.
@@ -16,7 +16,7 @@ export default class ApiUser {
16
16
  emptyUser: boolean;
17
17
  constructor(id?: string);
18
18
  getUserPermissions(): Promise<UserPayload>;
19
- useCustomPermissionLoader(customPermissionLoader: any): Promise<unknown>;
19
+ useCustomPermissionLoader(customPermissionLoader: any): Promise<UserPayload>;
20
20
  get businessModels(): string[] | undefined;
21
21
  get fleets(): string[] | undefined;
22
22
  get demandSources(): string[] | undefined;
@@ -44,6 +44,7 @@ class ApiUser {
44
44
  }
45
45
  const cachedResult = userCache.get(this.id);
46
46
  if (cachedResult) {
47
+ this.privatePermissions = cachedResult;
47
48
  return cachedResult;
48
49
  }
49
50
  const data = yield customPermissionLoader(this.id);
package/lib/user/index.js CHANGED
@@ -33,9 +33,6 @@ exports.middleware = (options = {}) => (req, res, next) => __awaiter(void 0, voi
33
33
  yield userObject.getUserPermissions();
34
34
  }
35
35
  }
36
- if (options.eagerLoadUserPermissions) {
37
- yield userObject.getUserPermissions();
38
- }
39
36
  if (options.eagerLoadUserPermissionsLegacy) {
40
37
  yield userObject.getUserPermissionsLegacy();
41
38
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@autofleet/zehut",
3
- "version": "1.7.0-beta1",
3
+ "version": "1.7.0-beta3",
4
4
  "description": "manage user's identity",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -1,25 +0,0 @@
1
- interface EntityPermissions {
2
- [key: string]: string[];
3
- }
4
- export interface UserPayload {
5
- businessModels: EntityPermissions;
6
- fleets: EntityPermissions;
7
- demandSources: EntityPermissions;
8
- createdAt?: string;
9
- }
10
- export default class ApiUser {
11
- id: string | undefined;
12
- privatePermissions: UserPayload | undefined;
13
- privatePermissionsLegacy: any;
14
- emptyUser: boolean;
15
- constructor(id?: string);
16
- getUserPermissions(): Promise<UserPayload>;
17
- get businessModels(): string[] | undefined;
18
- get fleets(): string[] | undefined;
19
- get demandSources(): string[] | undefined;
20
- getUserProperty(key: any): string[] | undefined;
21
- get permissions(): UserPayload | undefined;
22
- getUserPermissionsLegacy(): Promise<any>;
23
- get permissionsLegacy(): any;
24
- }
25
- export {};
@@ -1,73 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- /* eslint-disable consistent-return */
13
- const services_1 = require("../services");
14
- class ApiUser {
15
- constructor(id) {
16
- this.id = id;
17
- this.emptyUser = !!id;
18
- }
19
- getUserPermissions() {
20
- return __awaiter(this, void 0, void 0, function* () {
21
- if (!this.id) {
22
- return;
23
- }
24
- if (this.privatePermissions) {
25
- return this.privatePermissions;
26
- }
27
- const { data } = yield services_1.IdentityNetwork.get(`/api/v1/users/${this.id}/authorization-payload`);
28
- this.privatePermissions = data;
29
- return this.privatePermissions;
30
- });
31
- }
32
- get businessModels() {
33
- return this.getUserProperty('businessModels');
34
- }
35
- get fleets() {
36
- return this.getUserProperty('fleets');
37
- }
38
- get demandSources() {
39
- return this.getUserProperty('demandSources');
40
- }
41
- getUserProperty(key) {
42
- if (!this.privatePermissions) {
43
- throw new Error(`Cannot get ${key} without calling (async) getUserPermissions before`);
44
- }
45
- return Object.keys(this.privatePermissions[key] || {});
46
- }
47
- get permissions() {
48
- if (!this.privatePermissions) {
49
- throw new Error('Cannot get permissions without calling (async) getUserPermissions before');
50
- }
51
- return this.privatePermissions;
52
- }
53
- getUserPermissionsLegacy() {
54
- return __awaiter(this, void 0, void 0, function* () {
55
- if (!this.id) {
56
- return;
57
- }
58
- if (this.privatePermissionsLegacy) {
59
- return this.privatePermissionsLegacy;
60
- }
61
- const { data } = yield services_1.IdentityNetwork.get(`/api/v1/users/${this.id}/authorization-payload-legacy`);
62
- this.privatePermissionsLegacy = data;
63
- return this.privatePermissionsLegacy;
64
- });
65
- }
66
- get permissionsLegacy() {
67
- if (!this.privatePermissionsLegacy) {
68
- throw new Error('Cannot get permissionsLegacy without calling (async) getUserPermissionsLegacy before');
69
- }
70
- return this.privatePermissionsLegacy;
71
- }
72
- }
73
- exports.default = ApiUser;