@autofleet/zehut 1.7.3-beta4 → 1.7.3-beta5

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/index.d.ts CHANGED
@@ -10,14 +10,10 @@ declare const _default: {
10
10
  eagerLoadUserPermissions?: boolean;
11
11
  eagerLoadUserPermissionsLegacy?: boolean;
12
12
  customPermissionLoader?: import("./user/ApiUser").CustomPermissionLoader;
13
- appId?: string;
14
- clientSecret?: string;
15
13
  }) => (req: any, res: any, next: any) => Promise<any>;
16
14
  middlewareWithDecode: (options?: {
17
15
  eagerLoadUserPermissions?: boolean;
18
16
  eagerLoadUserPermissionsLegacy?: boolean;
19
- appId?: string;
20
- clientSecret?: string;
21
17
  returnErrorIfNoToken?: boolean;
22
18
  }) => (req: any, res: any, next: any) => Promise<void>;
23
19
  eagerLoadPermissionsMiddleware: (req: any, res: any, next: any) => Promise<any>;
@@ -27,6 +27,6 @@ export default class ApiUser {
27
27
  get permissions(): UserPayload | undefined;
28
28
  getUserPermissionsLegacy(): Promise<any>;
29
29
  get permissionsLegacy(): any;
30
- getUserAppPermissions(appId: any): Promise<any>;
30
+ getUserAppPermissions(appId: any, clientSecret: any): Promise<any>;
31
31
  }
32
32
  export {};
@@ -94,10 +94,10 @@ class ApiUser {
94
94
  }
95
95
  return this.privatePermissionsLegacy;
96
96
  }
97
- getUserAppPermissions(appId) {
97
+ getUserAppPermissions(appId, clientSecret) {
98
98
  return __awaiter(this, void 0, void 0, function* () {
99
99
  console.log('getUserAppPermissions1', appId, this.id);
100
- if (!this.id || !appId) {
100
+ if (!this.id || !appId || !clientSecret) {
101
101
  return;
102
102
  }
103
103
  const currentAppPermission = this.appPermission[appId];
@@ -113,6 +113,10 @@ class ApiUser {
113
113
  }
114
114
  const { data } = yield services_1.AutofleetApiNetwork.post(`/api/v1/apps/${appId}/get-user-payload`, {
115
115
  userId: this.id,
116
+ }, {
117
+ headers: {
118
+ 'x-autofleet-apps-secret': clientSecret,
119
+ },
116
120
  });
117
121
  console.log('getUserAppPermissions4', data);
118
122
  userCache.set(this.id, data);
@@ -3,14 +3,10 @@ export declare const middleware: (options?: {
3
3
  eagerLoadUserPermissions?: boolean;
4
4
  eagerLoadUserPermissionsLegacy?: boolean;
5
5
  customPermissionLoader?: CustomPermissionLoader;
6
- appId?: string;
7
- clientSecret?: string;
8
6
  }) => (req: any, res: any, next: any) => Promise<any>;
9
7
  export declare const middlewareWithDecode: (options?: {
10
8
  eagerLoadUserPermissions?: boolean;
11
9
  eagerLoadUserPermissionsLegacy?: boolean;
12
- appId?: string;
13
- clientSecret?: string;
14
10
  returnErrorIfNoToken?: boolean;
15
11
  }) => (req: any, res: any, next: any) => Promise<void>;
16
12
  export declare const appMiddleware: (options: {
package/lib/user/index.js CHANGED
@@ -18,7 +18,7 @@ const ApiUser_1 = __importDefault(require("./ApiUser"));
18
18
  const utils_1 = require("../utils");
19
19
  const tracer_1 = require("../tracer");
20
20
  exports.middleware = (options = {}) => (req, res, next) => __awaiter(void 0, void 0, void 0, function* () {
21
- const { eagerLoadUserPermissions, eagerLoadUserPermissionsLegacy, customPermissionLoader, appId, clientSecret, } = options;
21
+ const { eagerLoadUserPermissions, eagerLoadUserPermissionsLegacy, customPermissionLoader, } = options;
22
22
  const userId = req.headers['x-af-user-id'];
23
23
  const trace = tracer_1.newTrace('userPayload');
24
24
  if (!userId) {
@@ -37,10 +37,6 @@ exports.middleware = (options = {}) => (req, res, next) => __awaiter(void 0, voi
37
37
  if (eagerLoadUserPermissionsLegacy) {
38
38
  yield userObject.getUserPermissionsLegacy();
39
39
  }
40
- if (appId && clientSecret) {
41
- req.headers['x-autofleet-apps-secret'] = clientSecret;
42
- yield userObject.getUserAppPermissions(appId);
43
- }
44
40
  req.user = userObject;
45
41
  trace.context.set('userObject', userObject);
46
42
  // Added in order to support outbreak.
@@ -49,7 +45,7 @@ exports.middleware = (options = {}) => (req, res, next) => __awaiter(void 0, voi
49
45
  });
50
46
  exports.middlewareWithDecode = (options = {}) => (req, res, next) => __awaiter(void 0, void 0, void 0, function* () {
51
47
  var _a;
52
- const { eagerLoadUserPermissions, eagerLoadUserPermissionsLegacy, appId, clientSecret, returnErrorIfNoToken, } = options;
48
+ const { eagerLoadUserPermissions, eagerLoadUserPermissionsLegacy, returnErrorIfNoToken, } = options;
53
49
  const trace = tracer_1.newTrace('userPayload');
54
50
  let decoded;
55
51
  if (req.headers.authorization) {
@@ -88,10 +84,6 @@ exports.middlewareWithDecode = (options = {}) => (req, res, next) => __awaiter(v
88
84
  if (eagerLoadUserPermissionsLegacy) {
89
85
  yield userObject.getUserPermissionsLegacy();
90
86
  }
91
- if (appId && clientSecret) {
92
- req.headers['x-autofleet-apps-secret'] = clientSecret;
93
- yield userObject.getUserAppPermissions(appId);
94
- }
95
87
  req.user = userObject;
96
88
  trace.context.set('userObject', userObject);
97
89
  // Added in order to support outbreak.
@@ -147,7 +139,7 @@ exports.appMiddleware = (options) => (req, res, next) => __awaiter(void 0, void
147
139
  if (appId && clientSecret) {
148
140
  req.headers['x-autofleet-apps-secret'] = clientSecret;
149
141
  // Won't work until we find a better solution for identity ms
150
- yield userObject.getUserAppPermissions(appId);
142
+ yield userObject.getUserAppPermissions(appId, clientSecret);
151
143
  }
152
144
  req.user = userObject;
153
145
  trace.context.set('userObject', userObject);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@autofleet/zehut",
3
- "version": "1.7.3-beta4",
3
+ "version": "1.7.3-beta5",
4
4
  "description": "manage user's identity",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",