@autofleet/zehut 1.7.3-beta4 → 1.7.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/index.d.ts +0 -4
- package/lib/user/ApiUser.d.ts +1 -1
- package/lib/user/ApiUser.js +6 -6
- package/lib/user/index.d.ts +0 -4
- package/lib/user/index.js +3 -11
- package/package.json +1 -1
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>;
|
package/lib/user/ApiUser.d.ts
CHANGED
|
@@ -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 {};
|
package/lib/user/ApiUser.js
CHANGED
|
@@ -94,27 +94,27 @@ 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
|
-
|
|
100
|
-
if (!this.id || !appId) {
|
|
99
|
+
if (!this.id || !appId || !clientSecret) {
|
|
101
100
|
return;
|
|
102
101
|
}
|
|
103
102
|
const currentAppPermission = this.appPermission[appId];
|
|
104
|
-
console.log('getUserAppPermissions2', currentAppPermission);
|
|
105
103
|
if (currentAppPermission) {
|
|
106
104
|
return currentAppPermission;
|
|
107
105
|
}
|
|
108
106
|
const cachedResult = userCache.get(`${this.id}:${appId}`);
|
|
109
|
-
console.log('getUserAppPermissions3', cachedResult);
|
|
110
107
|
if (cachedResult) {
|
|
111
108
|
this.appPermission[appId] = cachedResult;
|
|
112
109
|
return cachedResult;
|
|
113
110
|
}
|
|
114
111
|
const { data } = yield services_1.AutofleetApiNetwork.post(`/api/v1/apps/${appId}/get-user-payload`, {
|
|
115
112
|
userId: this.id,
|
|
113
|
+
}, {
|
|
114
|
+
headers: {
|
|
115
|
+
'x-autofleet-apps-secret': clientSecret,
|
|
116
|
+
},
|
|
116
117
|
});
|
|
117
|
-
console.log('getUserAppPermissions4', data);
|
|
118
118
|
userCache.set(this.id, data);
|
|
119
119
|
this.appPermission[appId] = data;
|
|
120
120
|
return this.appPermission[appId];
|
package/lib/user/index.d.ts
CHANGED
|
@@ -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,
|
|
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,
|
|
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);
|